1

I'm using foreman in a Vagrant VM to run gunicorn. I have foreman start up as the last item when I provision the VM, but that leaves it logging to stdout. I'd prefer it to log to a log file and release the terminal to me. Then, should I want to see the foreman logs, I can tail the file.

I feel I must have missed something, as this doesn't sound like a difficult thing, but I'm stumped. I currently have to cancel, twice, to get out of the foreman logging, which is a messy end to the provisioning!

Phil Gyford
  • 13,432
  • 14
  • 81
  • 143

1 Answers1

2

The entries in your Procfile are just commands to run and you can tinker with them the same way you would on the command line.

So you could redirect all of the stdout for your unicorn process to /dev/null

Or redirect all output for the process with 2>&1 something like:

web: gunicorn myproject.wsgi 2>&1

In order for foreman to release the terminal back to you you'll need to run it in the background with:

foreman &
Shadwell
  • 34,314
  • 14
  • 94
  • 99
  • I can't work out how to do this. If the one command in my Procfile is `web: gunicorn myproject.wsgi > /dev/null` I still get output to the screen. I've tried directing it to a file too (but get an empty file). I've also tried using gunicorn's `--access-logfile` and `--error-logfile` settings: some output goes to those files, but I still get some output to screen. – Phil Gyford Apr 22 '15 at 20:17
  • It is possible that you're getting stderr output too. This answer might give you a few options to redirect absolutely all output : http://stackoverflow.com/questions/6674327/redirect-all-output-to-file – Shadwell Apr 22 '15 at 22:21
  • Closer, thanks… I can now send all the output to one file, but I still get one initial line (`08:30:55 web.1 | started with pid 21968`) and foreman doesn't release the terminal to me. I still have to Ctrl-C to get out of it. – Phil Gyford Apr 23 '15 at 08:32
  • You'd need to start foreman with `foreman &` to release the terminal. I'm pretty sure that the one line you're seeing is from foreman itself saying that it has started the process. – Shadwell Apr 23 '15 at 08:48
  • Ahh, that might be the trick... no time now until the weekend to double-check but it looks promising. I'll report back then. – Phil Gyford Apr 23 '15 at 12:27
  • That was it, thanks! I have my gunicorn process going `> /vagrant/gunicorn.log 2>&1` and foreman running with `&` and vagrant finishes nicely. If you want to update your answer I'll mark it as correct. – Phil Gyford Apr 26 '15 at 08:48