我有一个守护进程,我想让系统管理员来管理它。守护进程有自己的用户,并且用 ruby 完成,有自己的 rbenv 环境。守护进程的监督者配置如下:
[program:hooks]
command=/home/hooks/bin/run.sh
user=hooks
environment=HOME='/home/hooks',USER=hooks,PATH='/home/hooks/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
看起来/home/hooks/bin/run.sh
像:
#!/bin/bash -e
rbenv init -
cd /home/carehooks/src/
bundle install
thin --timeout 0 --environment 'production' --rackup `pwd`/config.ru --chdir examples/ start
现在,结果如下:
# supervisorctl start hooks
hooks: ERROR (abnormal termination)
# cat /var/log/supervisor/hooks-stderr---supervisor-e2Myrz.log
/bin/readlink: missing operand
Try `/bin/readlink --help' for more information.
/home/hooks/bin/run.sh: line 6: bundle: command not found
# cat /var/log/supervisor/hooks-stdout---supervisor-ndpvIv.log
export PATH="/home/hooks/.rbenv/shims:${PATH}"
source "/home/hooks/.rbenv/libexec/../completions/rbenv.bash"
rbenv rehash 2>/dev/null
function rbenv() {
command="$1"
if [ "$#" -gt 0 ]; then
shift
fi
case "$command" in
shell)
eval `rbenv "sh-$command" "$@"`;;
*)
command rbenv "$command" "$@";;
esac
}
是我的监督配置有问题,还是 rbenv 有问题?我怎样才能让两者共存?
答案1
rbenv 为所有命令(例如 ruby、bundle 等)创建 shim。这些 shim 位于单个目录中(默认为 ~/.rbenv/shims)。因此,您可以使用home/my_user/.rbenv/shims/command
参数调用以使用 rbenv 定义的命令版本。
请参阅附件中的我的conf示例程序。
[program:sample_program]
directory=/home/my_user/sample_dir
command=/home/my_user/.rbenv/shims/ruby server.rb
user=my_user
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/sample_program.out