Search code examples
ruby-on-railsnginxunicorn

How to refresh rails application after modify some file which deployed by Nginx?


Deployed a rails application using Nginx and Unicorn. Want to change config file. Is it necessary to restart Nginx? Or just do touch public/robots.txt?

If it works, why do touch public/robots.txt but not trigger at other files?


Solution

  • I think the touch tmp/restart.txt method is passenger specific. With unicorn, you can send a USR2 signal to it from the directory of the updated code to kill it, and restart the Unicorn instance.

    Depending on the OS you're running it in, sending the signal could be different (sig vs kill etc). Also assuming you use Capistrano for deployment:

    # Kill unicorn
    run "kill -s USR2 `cat #{unicorn_pid_file_location}`"
    
    # then restart unicorn with updated config
    run "#{unicorn_rails_or_unicorn} -c #{your_current_folder}/config/unicorn.rb -D -E production"