7

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.

zishe
  • 10,665
  • 12
  • 64
  • 103
Starkers
  • 10,273
  • 21
  • 95
  • 158
  • 1
    Not sure if its a typo but the file is `log/production.log` – Anand Shah May 01 '14 at 05:43
  • Sounds mostly like a permission issue, just for the purpose of testing set the permission on log/production.log to 777 and see if that makes a difference. – Anand Shah May 01 '14 at 06:33
  • I ran `sudo chmod 777 -R app_root` restarted the server, but still no logs in production! However, I do now get logs in development (I wasn't before) – Starkers May 01 '14 at 13:19
  • You didn't include your config. You should start server `puma -c config/puma.rb -e production` – zishe May 06 '14 at 12:33
  • @zishe Do you mean `pumactl -F config/puma.rb start` ? – Starkers May 06 '14 at 12:44
  • Don't know about `pumactl` config option: `-C, --config PATH Load PATH as a config file` Big `C`, i have a mistake. `puma -C config/puma.rb -e production` starts server with config (it's my path to it) it could be another. – zishe May 06 '14 at 12:48
  • Well you are right, I shouldn't be starting with `rails s` (force of habit :) ) but the problems still persist. Updated question.. – Starkers May 06 '14 at 12:49
  • @Starkers, so this `max threads: 16` changes to `20`? I want to know that config works. – zishe May 06 '14 at 13:01
  • Perhaps this `config.eager_load is set to nil` causing error in reading env config. Tty to set it to false, if there are no need in it in your app. – zishe May 06 '14 at 13:06
  • 1
    @zishe I set it to false, no difference. – Starkers May 07 '14 at 23:13
  • run this in your production rails console `Rails.logger.instance_variable_get(:@logdev).instance_variable_get(:@dev)` – phoet May 08 '14 at 01:45
  • @zishe Sadly not :( I put `bind` at the end of the file and restarted via pumactl but no, no logs. My log level is set to debug – Starkers May 11 '14 at 23:34

2 Answers2

3

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.

zishe
  • 10,665
  • 12
  • 64
  • 103
1

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.

makewavesnotwar
  • 975
  • 3
  • 8
  • 13