【问题标题】:unicorn server with Ubuntu init script带有 Ubuntu 初始化脚本的独角兽服务器
【发布时间】:2015-11-12 15:47:50
【问题描述】:

我根据这个digitalocean tutorial为独角兽创建了这个init.d脚本。

#!/bin/sh

### BEGIN INIT INFO
# Provides:          unicorn
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the unicorn app server
# Description:       starts unicorn using start-stop-daemon
### END INIT INFO

set -e

USAGE="Usage: $0 <start|stop|restart|upgrade|rotate|force-stop>"

# app settings
USER="deploy"
APP_NAME="appname"
APP_ROOT="/home/$USER/$APP_NAME"
ENV="production"

# environment settings
PATH="/home/$USER/.rbenv/shims:/home/$USER/.rbenv/bin:$PATH"
CMD="cd $APP_ROOT && bundle exec unicorn -c config/unicorn.rb -E $ENV -D"
PID="$APP_ROOT/shared/pids/unicorn.pid"
OLD_PID="$PID.oldbin"

# make sure the app exists
cd $APP_ROOT || exit 1

sig () {
  test -s "$PID" && kill -$1 `cat $PID`
}

oldsig () {
  test -s $OLD_PID && kill -$1 `cat $OLD_PID`
}

case $1 in
  start)
    sig 0 && echo >&2 "Already running" && exit 0
    echo "Starting $APP_NAME"
    su - $USER -c "$CMD"
    ;;
  stop)
    echo "Stopping $APP_NAME"
    sig QUIT && exit 0
    echo >&2 "Not running"
    ;;
  force-stop)
    echo "Force stopping $APP_NAME"
    sig TERM && exit 0
    echo >&2 "Not running"
    ;;
  restart|reload|upgrade)
    sig USR2 && echo "reloaded $APP_NAME" && exit 0
    echo >&2 "Couldn't reload, starting '$CMD' instead"
    $CMD
    ;;
  rotate)
    sig USR1 && echo rotated logs OK && exit 0
    echo >&2 "Couldn't rotate logs" && exit 1
    ;;
  *)
    echo >&2 $USAGE
    exit 1
    ;;
esac

现在(脚本名称是uicorn_app

sudo update-rc.d `unicorn_app` defaults

有效。但每当我尝试

 $ sudo service unicorn_app start
 Starting app
 -su bundle: command not found

但是我可以通过

阻止它
$ sudo service unicorn_app stop

在我手动启动它之后

RAILS_ENV=production rails s -b ip.ip.ip.ip

我通过 rbenv 和 PATH/etc/local 上安装了 ruby on rails 第一个条目重定向到正确的目录:

/usr/local/rbenv/shims
/usr/lcoal/rbenv/bin

我需要更改哪些我的脚本找到捆绑包?既然我认为 PATH 是正确的,还有什么可能出错的?提前感谢您的帮助!

【问题讨论】:

    标签: ruby ubuntu unicorn init.d


    【解决方案1】:

    好的,解决方案是与 rbenv 安装有关。我需要将PATHRBENV_ROOT 添加到我的~/.bash_profile 中。添加它们后,我可以通过sudo service unicorn_app start启动独角兽

    【讨论】:

      猜你喜欢
      • 2012-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-27
      • 2013-02-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多