Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Production log is blank?

My puma config:

path = Dir.pwd + "/tmp/puma/"

threads 0,20
environment "production"
daemonize true
drain_on_shutdown true

bind  "unix://" + path + "socket/puma.sock"
pidfile path + "pid/puma.pid"
state_path path + "pid/puma.state"

My environments/production.rb

MyApp::Application.configure do    
  config.log_level = :debug
end

I start my server:

starkers@ubuntu:~/Desktop/myspp$ pumactl -F config/puma.rb start
=> Booting Puma
=> Rails 4.0.2 application starting in production on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:

  * development - set it to false
  * test - set it to false (unless you use a tool that preloads your test environment)
  * production - set it to true

Puma 2.8.2 starting...
* Min threads: 0, max threads: 16
* Environment: production
* Listening on tcp://0.0.0.0:3000

I browse about my app. And my log/production.log is blank. Not sure why?

Directory access is 0777 throughout my app.

No idea what is causing this. Really need logs (obviously). Happening locally and remotely so it's something to do with my configuration. However I'm not sure what configuration. Is there anything in puma/ubuntu/rails that could be causing this?

development.log works perfectly.

I've copy pasted my development.rb to my production.rb file. Literally identical. Okay? Identical development.rb and production .rb And yet:
RAILS_ENV=development rails s

populates development.log

and

RAILS_ENV=production rails s

leaves production.log as empty as Kim Kardashian's head.

like image 720
Starkers Avatar asked May 01 '14 05:05

Starkers


2 Answers

Set bind at the end of config file:

path = Dir.pwd + "/tmp/puma/"

threads 0,20
environment "production"
daemonize true
drain_on_shutdown true

pidfile path + "pid/puma.pid"
state_path path + "pid/puma.state"
bind  "unix://" + path + "socket/puma.sock"

I used command pumactl -F config/puma.rb start to start server (i guess there is no difference, but anyway).

And i would recommend to use #{} for path:

pidfile "#{path}pid/puma.pid"
state_path "#{path}pid/puma.state"
bind  "unix://#{path}socket/puma.sock"

but it's your choice.

Hope it helps (for me you config didn't work too).

you can also add Puma logs:

stdout_redirect "#{Dir.pwd}/log/puma.stdout.log", "#{Dir.pwd}/log/puma.stderr.log"

Add this line before bind.

like image 53
zishe Avatar answered Oct 24 '22 07:10

zishe


If you want to add the output of the server to a log, the easiest way to do this is by telling your system to do exactly that. Running your server start command like:

pumactl -F config/puma.rb start >> log/development.log

Will append each line of output from your server to the development log. Though to make things easier to debug, you may want to give each server its own log such as log/puma.log. If you do, you may wish to rewrite the file from scratch every time you start the server instead of keeping a cumulative log, if that's the case just turn the >> into a > such as:

pumactl -F config/puma.rb start > log/puma.log

However, if you have your system set up to automatically restart the server if it fails, using > will overwrite the log for what might have caused the crash when the server restarts.

Similarly, you can get your production.log working by starting your rails server like:

RAILS_ENV=production rails s >> log/production.log

If you want to run your server in the background like you might in your production environment, you can add a & character to the end like:

pumactl -F config/puma.rb start > log/puma.log &

If you do this you'll probably want to store the process identifier so you can kill the server later as ^C doesn't work for background processes. To store the process id, create another empty file somewhere like lib/pids/puma.pid and then export the process id of that puma server to the empty file like:

pumactl -F config/puma.rb start > log/puma.log &
echo $! > lib/pids/puma.pid

You would then be able to kill the server with:

kill `cat lib/pids/puma.pid`

It is important to remember that even if you append the output of the server to your development.log file, it will not show up in the output of your development rails server. If you want a live view of your log for debugging, you can use the tailf command such as:

tailf log/puma.log

For more information on the command line interface, the Command Line Crash Course is a good resource.

like image 39
makewavesnotwar Avatar answered Oct 24 '22 08:10

makewavesnotwar