54

When I run foreman I get the following:

 > foreman start
 16:47:56 web.1     | started with pid 27122

Only if I stop it (via ctrl-c) it shows me what is missing:

^CSIGINT received
16:49:26 system    | sending SIGTERM to all processes
16:49:26 web.1     | => Booting Thin
16:49:26 web.1     | => Rails 3.0.0 application starting in development on http://0.0.0.0:5000
16:49:26 web.1     | => Call with -d to detach
16:49:26 web.1     | => Ctrl-C to shutdown server
16:49:26 web.1     | >> Thin web server (v1.3.1 codename Triple Espresso)
16:49:26 web.1     | >> Maximum connections set to 1024
16:49:26 web.1     | >> Listening on 0.0.0.0:5000, CTRL+C to stop
16:49:26 web.1     | >> Stopping ...
16:49:26 web.1     | Exiting
16:49:26 web.1     | >> Stopping ...

How do I fix it?

davejagoda
  • 2,420
  • 1
  • 20
  • 27
ijverig
  • 2,795
  • 3
  • 18
  • 26
  • If you are launching multiple tasks that require the whole rails stack, it might take a while to launch everything. The foreman output is instantaneous, but your background jobs wont be faster than usual. In my case, I had to wait about 2 minutes. So... wait for it. – Benjamin Crouzier Dec 16 '13 at 16:06

6 Answers6

50

I’ve been able to resolve this issue by 2 different ways:

  1. From https://github.com/ddollar/foreman/wiki/Missing-Output:

    If you are not seeing any output from your program, there is a likely chance that it is buffering stdout. Ruby buffers stdout by default. To disable this behavior, add this code as early as possible in your program:

    # ruby
    $stdout.sync = true
    
  2. By installing foreman via the heroku toolbelt package

But I still don’t know what’s happening nor why this 2 ways above resolved the issue…

ijverig
  • 2,795
  • 3
  • 18
  • 26
  • 5
    +1 - Thanks so much! Per @Earle Clubb below, I added the `$stdout.sync = true` line to my `config/environments/development.rb` file and it works perfectly! – Topher Fangio Jan 03 '13 at 15:26
  • 2
    Now only the 1 works. May be 2nd used to work when Heroku Toolbelt where having older version of foreman. – Saneef Feb 10 '13 at 05:04
21

My solution was to put $stdout.sync = true at the top of config/environments/development.rb.

Then everything that loads the development environment (incluing thin) will not buffer stdout.

Earle Clubb
  • 451
  • 5
  • 7
16

"Foreman will display to the terminal output anything written to stdout by the processes it launches." - ddollar See foreman-issues#57

BTW, you can use tailf into Procfile to see logs

web: bundle exec rails server thin -p $PORT
log: tail -f log/development.log

Tip: tailf doesn't exist in OSX, using tail -f -n 40 log/development.log works.

julionc
  • 349
  • 1
  • 4
  • 1
    This serves the same purpose but doesn't change that rails still isn't flushing its buffers for me for some reason. When I run 'rails console' and run STDOUT.sync it returns true so it should be flushing, but foreman still isn't writing anything from the worker. – jrbalsano Jun 03 '12 at 20:43
  • 2
    Rails **only** flushes writes to the logfile when the next rack request is finishing, it's handled by the Rails::Rack::Logger middleware. Which worker are you talk? Resque redis ? – julionc Jun 06 '12 at 18:21
  • Sorry, by worker I meant the tail -f that's running. Not sure why but I've definitely had a dev environment where web was writing all the messages I'm currently seeing output by log. – jrbalsano Jun 07 '12 at 00:40
5

I also had the same problem but with a different solution. (ruby 1.9.2p290, rails 3.1.0, ubuntu 10.04.3)

I changed the line in my Procfile from:

web: bundle exec thin start -p $PORT

to:

web: bundle exec rails server thin -p $PORT

and it no longer gave me an issue.

Dan
  • 51
  • 1
  • Nope. Didn’t work. Shows me some INFO message on webrick, but it still only shows the booting message after a ctrl-c… – ijverig Jan 07 '12 at 00:56
  • This one worked for me. I started server with `bundle exec puma ...` and `rails s ...` did the trick – Maxence Jan 17 '21 at 19:57
4

If you are using Foreman to run a Python project, rather than a Ryby project, and you're having the same issue, here are some solutions for you. If you are using a Procfile to invoke the python CLI directly, then you can use the '-u' option to avoid stdout buffering:

python -u script.py

If you are using a Procfile to manage a WSGI server, such as invoking gunicorn, flask, bottle, eve, etc., then you can add a ".env" file to the root of your python project, containing the following:

PYTHONUNBUFFERED=True
jsears
  • 4,511
  • 2
  • 31
  • 36
4

I have the same problem (ruby 1.9.3-p0, rails 3.2rc2, OSX 10.7).

Resolved the issue by using foreman-0.27.0 by adding this line into my Gemfile.

gem 'foreman', '0.27.0'
Gerry Shaw
  • 9,178
  • 5
  • 41
  • 45
  • Mine worked when I installed the "more general foreman” from the heroku toolbelt package. The one from the gems didtn’t… – ijverig Jan 15 '12 at 21:56