Unicorn使用RVM安装脚本 - 哪个可执行文件?

时间:2011-04-15 11:48:13

标签: ruby-on-rails rvm ubuntu-10.04 unicorn

我正在尝试为unicorn(在Ubuntu上)运行一个init脚本,并将unicorn安装为gem:

/home/tim/.rvm/gems/ruby-1.9.2-p180@polco/bin/unicorn

我的初始化脚本是:

#! /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 `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

使用rvm可执行文件,整个操作对我来说似乎很脆弱。 rvm有类似$ CURRENT_RVM_PATH吗?

2 个答案:

答案 0 :(得分:1)

O.k。我为我解决了这个问题。如果我是root用户,我就不再关心了,并且决定以讽刺的方式运行这个用户“乘客”并且我需要运行unicorn_rails。

这是我的启动脚本:

#! /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

要执行此操作 - 我现在有简单的capistrano任务:

  desc "restart unicorn"
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "#{current_path}/unicorn_exec restart"
  end

  after "deploy:restart","unicorn:restart"

最后一个问题我是为什么我必须重启unicorn_rails。我以为我可以通过以下方式重新加载:kill -HUP cat $PID,但是一切只有在重新启动时才有效。

答案 1 :(得分:1)

由于谷歌可能会为其他人找到这个问题,这是我在3台不同服务器上使用的独角兽重启脚本。我只需要添加USR2。回购被称为eunic,我可能会在以后修改它。

这就是说,这是另一种方法。