0

I'm running a haskell-based build using cabal the following way in dev mode on ubuntu 20.04:

cabal new-run -- exe:live-docs \
  --database-url='postgres://<user>:<password>@<host>:<port>/<dbname>' \
  serve --enable-admin --admin-assets-dir=../admin/static

What is the best practice to keep the cabal session working in the background (keep-alive) for production use?

I have looked into the Cabal documentation in vain.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
mediaroot
  • 435
  • 8
  • 17
  • Why do you think this has anything to do with `cabal`? It is your program, `live-docs`, that decides when to exit, not `cabal`. – Daniel Wagner May 15 '21 at 18:54
  • When executing `cabal new-run` the app keeps running until I close the terminal. I'm new to haskell. With `node.js` I use `PM2`. – mediaroot May 15 '21 at 18:59
  • That is a statement about your shell, not `cabal` (and not your terminal). Look into `nohup`, double forking, or your shell's documentation about job control... or just don't have its launch be controlled by a shell in a terminal, but rather by systemd or whatever init system you are into. – Daniel Wagner May 15 '21 at 19:00
  • `nohup` might help to keep the `cabal new-run` shell script alive. However, the `cabal` commands throw console logs. For production use it is not a good practice as far as I know. I was hoping to see a command option such as `cabal new-run --no-logs --keep-alive` at least! – mediaroot May 15 '21 at 19:04

1 Answers1

1

If the goal is to avoid cabal's output (as described in your comments), you have two quick options:

  1. Use -v0 to ask it not to output anything. It will still produce output if building your program fails.

    cabal run -v0 live-docs -- --db etc
    
  2. Use cabal to build, and optionally copy it somewhere central, then just... run your program. This is what most people do. To build and run:

    cabal build live-docs # this produces output and is done once
    
    # the next three are essentially equivalent options. you do one of them each
    # time you want to start your program
    `cabal list-bin live-docs` --db etc # OR
    cabal exec live-docs -- --db etc # OR
    ./dist-newstyle/<poke around a bit>/live-docs --db etc
    

    To build and copy somewhere central:

    cabal install exe:live-docs # done once, produces output
    
    live-docs --db etc # each time you want to start your program
    
Daniel Wagner
  • 145,880
  • 9
  • 220
  • 380
  • Thanks a lot. `cabal run -v0 ...` is what I was mainly looking for as I still want to keep using cabal while developing in cloud. – mediaroot May 15 '21 at 19:22