Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to restart unicorn manually

I'm not confident that unicorn is restarting properly when I run cap deploy as certain changes are not showing in the app, therefore I wanted to restart unicorn manually on my remote server. I have navigated into etc/init.d and see a listing for unicorn_myapp but it's not a directory (i.e. I can't cd into it). Based on the code below from my deploy.rb file, is there something I can do from here to restart unicorn?

I tried to do run unicorn_myapp restart but it said run isn't a command

namespace :deploy do
  %w[start stop restart].each do |command|
    desc "#{command} unicorn server"
    task command, roles: :app, except: {no_release: true} do
      run "/etc/init.d/unicorn_#{application} #{command}"
    end
  end
like image 823
BrainLikeADullPencil Avatar asked Oct 14 '13 01:10

BrainLikeADullPencil


3 Answers

you didn't list the OS. but one of the following should work.

you will need to be root / use sudo

/etc/init.d/unicorn_myapp restart 


/etc/init.d/unicorn_myapp stop 
/etc/init.d/unicorn_myapp start 


service unicorn_myapp restart

service unicorn_myapp stop
service unicorn_myapp start

Try the restart versions first, but depending upon how the init script was written it might not have a restart command, if that doesn't work you can do the stop / start version.

like image 200
Doon Avatar answered Oct 28 '22 08:10

Doon


Alternatively, instead of relying on /etc/init.d... scripts which are OS dependent, a simple way to restart unicorn is to send HUP (1) signal to its master process.

Here is for instance how I reload an app automatically after a git push via post-receive hook:

#!/bin/sh
unicorn_pid=`cat /tmp/pids/unicorn.pid`
echo "Restarting Unicorn ($unicorn_pid)"
kill -HUP $unicorn_pid

In your case, /etc/init.d/unicorn_myapp restart script is probably doing this. Check the unicorn.conf for the location of its pidfile.

For more details, see unicorn SIGNALS documentations

like image 33
Vincent Guerci Avatar answered Oct 28 '22 07:10

Vincent Guerci


You might have to be root, but it should just be /etc/init.d/unicorn_myapp restart (don't include run, which is not a shell command).

like image 32
wwwslinger Avatar answered Oct 28 '22 07:10

wwwslinger