2

I'm using the init.d script provided (the init.d script from the sidekiq github repo), but I am on an ubuntu system with RVM installed system wide.

I cannot seem to figure out how to cd into my app directory and issue the command without there being some complaining in the log and nothing actually starting.

Question: What should the startup command for sidekiq look like in my init.d script when I am using RVM? My user is named ubuntu. Currently I have this in my init.d script:

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


}

My sidekiq.log gives me this error:Could not locate Gemfile. However, I print the working directory and I am most definitely in my app's current directory, according to the echo pwd, at the time this command is executed.

When I take out the su - ubuntu -c [command here], I get this error:

/usr/bin/env: ruby_noexec_wrapper: No such file or directory

My solution is to just start the process manually. When I manually cd into my app directory and issue this command:

bundle exec sidekiq -d -L log/sidekiq.log -P tmp/pids/sidekiq.pid

things go as planned, and then

sudo /etc/init.d/sidekiq status

tells me things are up and running.

Also, sudo /etc/init.d/sidekiq stop and status work as expected.

4

2 回答 2

3

几个月前,我写了一篇关于为 Sidekiq 编写 init.d 脚本的经验的博客文章,但是我使用的是 rbenv 而不是 RVM。

https://cdyer.co.uk/blog/init-script-for-sidekiq-with-rbenv/

我认为您应该能够使用几乎相同的东西,除了修改用户名和应用程序目录变量。

于 2013-08-15T20:30:14.360 回答
2

使用包装器:

BUNDLER=/usr/local/rvm/wrappers/ruby-1.9.3-p385/bundle

如果捆绑器包装器不可用,请使用以下命令生成它:

rvm wrapper ruby-1.9.3-p385 --no-links bundle # OR:
rvm wrapper ruby-1.9.3-p385 --no-links --all

您可以使用别名使其更容易:

rvm alias create my_app 1.9.3-p385

然后像这样使用它:

BUNDLER=/usr/local/rvm/wrappers/my_app/bundle

这样,当应用程序 ruby​​ 更改时,您不必更改脚本 - 只需更新别名,在 rvm-capistrano => https://github.com/wayneeseguin/rvm-capistrano/#创建应用程序别名和包装器

于 2013-08-03T23:52:00.850 回答