我正在使用提供的 init.d 脚本( init.d script from the sidekiq github repo ),但我使用的是系统范围内安装了 RVM 的 ubuntu 系统。
我似乎无法弄清楚如何 cd 进入我的应用程序目录并发出命令,而不会在日志中出现一些提示并且实际上没有任何启动。
问题:当我使用 RVM 时,我的 init.d 脚本中 sidekiq 的启动命令应该是什么样子?我的用户名为 ubuntu。目前我的 init.d 脚本中有这个:
START_CMD="$BUNDLE exec $SIDEKIQ"
# where bundle is /usr/local/rvm/gems/ruby-1.9.3-p385/bin/bundle
# and sidekiq is sidekiq
# I've also tried with the following args: -e $APP_ENV -P $PID_FILE -C $APP_CONFIG/sidekiq.yml -d -L $LOG_FILE"
RETVAL=0
start() {
status
if [ $? -eq 1 ]; then
[ `id -u` == '0' ] || (echo "$SIDEKIQ runs as root only .."; exit 5)
[ -d $APP_DIR ] || (echo "$APP_DIR not found!.. Exiting"; exit 6)
cd $APP_DIR
echo "Starting $SIDEKIQ message processor .. "
echo "in dir `pwd`"
su - ubuntu -c "$START_CMD >> $LOG_FILE 2>&1 &"
RETVAL=$?
#Sleeping for 8 seconds for process to be precisely visible in process table - See status ()
sleep 8
[ $RETVAL -eq 0 ] && touch $LOCK_FILE
return $RETVAL
else
echo "$SIDEKIQ message processor is already running .. "
fi
}
我的 sidekiq.log 给出了此错误:无法找到 Gemfile
。但是,我打印了工作目录,并且根据 echo pwd,在执行此命令时,我绝对位于应用程序的当前目录中。
当我取出 su - ubuntu -c [此处的命令]时,出现此错误:
/usr/bin/env: ruby_noexec_wrapper: No such file or directory
我的解决方案是手动启动该过程。当我手动 cd 进入我的应用程序目录并发出此命令时:
捆绑执行 sidekiq -d -L log/sidekiq.log -P tmp/pids/sidekiq.pid
事情按计划进行,然后
sudo/etc/init.d/sidekiq status
告诉我事情已经启动并正在运行。
此外,sudo/etc/init.d/sidekiq stop 和 status 按预期工作。
最佳答案
几个月前,我写了一篇博客文章,介绍了为 Sidekiq 编写 init.d 脚本的经验,但我使用的是 rbenv 而不是 RVM。
https://cdyer.co.uk/blog/init-script-for-sidekiq-with-rbenv/
我认为除了修改用户名和应用程序目录变量之外,您应该能够使用几乎相同的东西。
关于ruby-on-rails - 使用 RVM 通过 init.d 脚本管理 sidekiq,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18038170/