Unicorn Install Script with RVM -- which executable?
I am trying to get an init script running for unicorn (on Ubuntu) with unicorn installed as a gem:
/home/tim/.rvm/gems/ruby-1.9.2-p180@polco/bin/unicorn
My init script is:
#! /bin/sh ### BEGIN INIT INFO # Provides: unicorn # Required-Start: $local_fs $remote_fs $network $syslog # Required-Stop: $local_fs $remote_fs $network $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts the unicorn web server # Description: starts unicorn ### END INIT INFO PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/home/tim/.rvm/gems/ruby-1.9.2-p180@polco/bin/unicorn DAEMON_OPTS="-c /home/deployer/shop/current/unicorn.rb -E production -D" NAME=unicorn_rails DESC=unicorn_rails PID=/home/deployer/shop/shared/pids/unicorn.pid case "$1" in start) echo -n "Starting $DESC: " $DAEMON $DAEMON_OPTS echo "$NAME." ;; stop) echo -n "Stopping $DESC: " kill -QUIT `ca开发者_Python百科t $PID` echo "$NAME." ;; restart) echo -n "Restarting $DESC: " kill -QUIT `cat $PID` sleep 1 $DAEMON $DAEMON_OPTS echo "$NAME." ;; reload) echo -n "Reloading $DESC configuration: " kill -HUP `cat $PID` echo "$NAME." ;; *) echo "Usage: $NAME {start|stop|restart|reload}" >&2 exit 1 ;; esac exit 0
The whole operation seems fragile to me with the rvm executable. Does rvm have something like $CURRENT_RVM_PATH?
O.k. i solved this for me. I stopped caring if I was root or not and decided to run this as, ironically, the user 'passenger' and I needed to run unicorn_rails.
here is my startup script:
#! /bin/sh ### BEGIN INIT INFO # Provides: unicorn # Required-Start: $local_fs $remote_fs $network $syslog # Required-Stop: $local_fs $remote_fs $network $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts the unicorn web server # Description: starts unicorn ### END INIT INFO PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin #DAEMON=/home/tim/.rvm/gems/ruby-1.9.2-p180@polco/bin/unicorn DAEMON=/home/passenger/.rvm/gems/ruby-1.9.2-p180/bin/unicorn_rails DAEMON_OPTS="-c /home/passenger/polco/current/config/unicorn_tacitus.rb -E production -D" NAME=unicorn_rails DESC=unicorn_rails PID=/home/passenger/polco/shared/pids/unicorn.pid case "$1" in start) echo -n "Starting $DESC: " $DAEMON $DAEMON_OPTS echo "$NAME." ;; stop) echo -n "Stopping $DESC: " kill -QUIT `cat $PID` echo "$NAME." ;; restart) echo -n "Restarting $DESC: " kill -QUIT `cat $PID` sleep 1 $DAEMON $DAEMON_OPTS echo "$NAME." ;; reload) echo -n "Reloading $DESC configuration: " kill -HUP `cat $PID` echo "$NAME." ;; *) echo "Usage: $NAME {start|stop|restart|reload}" >&2 exit 1 ;; esac exit 0
To execute this -- I now have the simple capistrano task:
desc "restart unicorn" task :restart, :roles => :app, :except => { :no_release => true } do run "#{current_path}/unicorn_exec restart" end after "deploy:restart","unicorn:restart"
The last question I is why I have to restart unicorn_rails. I thought I could reload via: kill -HUP cat $PID
, but everything only works if I restart.
Since google might find this question for other people, here is my unicorn restart script I'm using on 3 different servers. I just need to add USR2 The repo is called eunic and i may hack on this later.
All that to say, here is another way to do it.
精彩评论