使用upstart脚本守护sidekiq - 无法正常工作

时间:2014-06-12 08:14:56

标签: ruby-on-rails ubuntu sidekiq upstart

我正在尝试使用this示例之后的两个upstart脚本守护sidekiq。 基本上,工人服务开始了固定数量的sidekiq服务。

问题是sidekiq脚本在我启动sidekiq的代码行失败。我试图直接在bash中运行命令,它运行正常。

我尝试了所有不同的注释行,但都没有。

所以我的问题是我做错了什么?我在哪里可以看到错误消息?

这是我修改过的sidekiq脚本:

# /etc/init/sidekiq.conf - Sidekiq config

# This example config should work with Ubuntu 12.04+.  It
# allows you to manage multiple Sidekiq instances with
# Upstart, Ubuntu's native service management tool.
#
# See workers.conf for how to manage all Sidekiq instances at once.
#
# Save this config as /etc/init/sidekiq.conf then mange sidekiq with:
#   sudo start sidekiq index=0
#   sudo stop sidekiq index=0
#   sudo status sidekiq index=0
#
# or use the service command:
#   sudo service sidekiq {start,stop,restart,status}
#

description "Sidekiq Background Worker"

respawn
respawn limit 15 5

# no "start on", we don't want to automatically start
stop on (stopping workers or runlevel [06])

# TERM and USR1 are sent by sidekiqctl when stopping sidekiq.  Without declaring these    as normal exit codes, it just respawns.
normal exit 0 TERM USR1

instance $index

script
exec /bin/bash <<EOT
  # use syslog for logging
  # exec &> /dev/kmsg

  # pull in system rbenv
  # export HOME=/home/deploy
  # source /etc/profile.d/rbenv.sh

  cd /home/rails
  touch /root/sidekick_has_started
  sidekiq -i ${index} -e production
  # exec sidekiq -i ${index} -e production
  # exec /usr/local/rvm/gems/ruby-2.0.0-p353/gems/sidekiq-3.1.3/bin/sidekiq -i ${index} -e production
  touch /root/sidekick_has_started_2
EOT
end script

1 个答案:

答案 0 :(得分:3)

你是对的,需要加载RVM env。试试这个:

.....    
.....

script
exec /bin/bash <<EOT

  #export HOME=/home/deploy
  source /usr/local/rvm/environments/ruby-2.0.0-p353@global

  cd /home/rails
  exec sidekiq -i ${index} -e production

.....    
.....

有效吗?