[英]Unicorn service upstart script throws “-su: bundle: command not found”
我最近在DigitalOcean上创建了一个VPS来托管rails应用程序。 我按照他们的指南用我的应用程序设置了Unicorn。 https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-unicorn-and-nginx-on-ubuntu-14-04
我运行sudo service unicorn_appxyz start
时出现问题。 给出的错误是-su: bundle: command not found
我跟踪了init.d脚本并在终端中粘贴了评估的服务器启动命令,并且在用户joe (安装rbenv的用户和应用程序的所有者)下执行时,它可以正常工作。 评估的命令是
su - joe -c cd /home/joe/appxyz && bundle exec unicorn -c config/unicorn.rb -E production -D
我然后sudo su - 进入root用户并运行service unicorn_appxyz start
错误当然是一样的。 然后我在root下运行了evaluate命令,它返回了这个错误
The program 'bundle' is currently not installed. You can install it by typing:
apt-get install bundler
看来脚本没有切换用户? 这可能是我启动VPS时独角兽无法启动的原因。
完整的独角兽新贵脚本在这里:
#!/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="joe"
APP_NAME="appxyz"
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
更多相关信息
这是用户joe下的ruby,rails和bundler的路径。 在根目录下,他们找不到。
joe@vps:~$ which ruby
/home/joe/.rbenv/shims/ruby
joe@vps:~$ which rails
/home/joe/.rbenv/shims/rails
joe@vps:~$ which bundle
/home/joe/.rbenv/shims/bundle
有意义的是在root用户下找不到bundler,但upstart命令应该切换到用户'joe'来运行bundle命令。 这是我不理解的部分。
我发现了这个问题。 说明如下,
启动时root用户首先su - 进入rails用户(在本例中为'joe')然后执行bundle以启动unicorn。 rbenv是单用户,只有'joe'安装了bundle。 bundle的路径可能存储在我的.bashrc文件中。 但是.bashrc文件不是通过su登录而调用的 - 并且导致bundle未安装错误。
我在.profile中包含了与rbenv相关的路径。 这种方式当root su - into'joe'时,路径被加载。
在Unbutu我用这个内容创建了我的文件/etc/profile.d/rbenv.sh:
export RBENV_ROOT=/home/YOUR_USER_PATH/.rbenv
export PATH=$RBENV_ROOT/shims:$RBENV_ROOT/bin:$PATH
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.