我正在尝试设置使用capistrano部署的rails测试服务器 .
我知道我的capistrano脚本正在运行,因为它使用相同的脚本部署到 生产环境 服务器没有问题 .
在部署期间,应该启动独角兽,以执行此操作
sudo service unicorn_appname start
叫做 .
这会出现以下错误: Job for unicorn_appname.service failed because the control process exited with error code. See "systemctl status unicorn_appname.service" and "journalctl -xe" for details.
当我检查 sudo journalctl -u unicorn_appname
是看到的
systemd[1]: Starting LSB: starts the unicorn web server...
su[3790]: Successful su for user by root
su[3790]: + ??? root:user
su[3790]: pam_unix(su:session): session opened for user user by (uid=0)
unicorn_appname[3787]: -su: bundle: command not found
systemd[1]: unicorn_appname.service: Control process exited, code=exited status=127
systemd[1]: Failed to start LSB: starts the unicorn web server.
systemd[1]: unicorn_appname.service: Unit entered failed state.
systemd[1]: unicorn_appname.service: Failed with result 'exit-code'.
/etc/init.d/unicorn_appname
存在且 /etc/init.d
时
./unicorn_appname start
有效sudo ./unicorn_appname start
然而给出 -su: bundle: command not found
但 which bundle
和 sudo which bundle
都显示相同的路径( /home/user/.rbenv/shims/bundle
)
如果可能,我不想更改脚本,因为它们可以在其他服务器上运行 . 所以我认为新服务器上有一些设置不同或缺失 - 但我不知道在哪里看 .
这是 unicorn_appname
的内容:
#!/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
set -e
# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/home/user/apps/appname/current
PID_DIR=$APP_ROOT/tmp/pids
PID=$PID_DIR/unicorn.pid
CMD="cd $APP_ROOT; bundle exec unicorn -D -c /home/user/apps/appname/shared/config/unicorn.rb -E production"
AS_USER=user
set -u
OLD_PIN="$PID.oldbin"
sig () {
test -s "$PID" && kill -$1 `cat $PID`
}
oldsig () {
test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`
}
workersig () {
workerpid="$APP_ROOT/tmp/pids/unicorn.$2.pid"
test -s "$workerpid" && kill -$1 `cat $workerpid`
}
run () {
if [ "$(id -un)" = "$AS_USER" ]; then
eval $1
else
su -c "$1" - $AS_USER
fi
}
case "$1" in
start)
sig 0 && echo >&2 "Already running" && exit 0
run "$CMD"
;;
stop)
sig QUIT && exit 0
echo >&2 "Not running"
;;
force-stop)
sig TERM && exit 0
echo >&2 "Not running"
;;
kill_worker)
workersig QUIT $2 && exit 0
echo >&2 "Worker not running"
;;
restart|reload)
sig USR2 && echo reloaded OK && exit 0
echo >&2 "Couldn't reload, starting '$CMD' instead"
run "$CMD"
;;
upgrade)
if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
then
n=$TIMEOUT
while test -s $OLD_PIN && test $n -ge 0
do
printf '.' && sleep 1 && n=$(( $n - 1 ))
done
echo
if test $n -lt 0 && test -s $OLD_PIN
then
echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds"
exit 1
fi
exit 0
fi
echo >&2 "Couldn't upgrade, starting '$CMD' instead"
run "$CMD"
;;
reopen-logs)
sig USR1
;;
*)
echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
exit 1
;;
esac
您还需要更多信息吗?
编辑:
user
是我用来部署的用户 . 对于此系统上的 root
,未安装任何内容 . 这可能是问题吗?
2 回答
我想我找到了解决方案:
在prod服务器上,我有一个
/etc/profile.d/rbenv.sh
在新服务器上丢失了 .这是它的内容:
我认为你的问题(可能)是:
假设您在测试服务器上使用的是相同的命令,则需要更改要测试的环境 .