【问题标题】:daemonizing sidekiq with upstart script - is not working用 upstart 脚本守护 sidekiq - 不工作
【发布时间】:2014-06-13 00:44:58
【问题描述】:

我正在尝试使用 this 示例之后的两个新贵脚本来守护 sidekiq。 基本上,worker 服务会启动固定数量的 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

【问题讨论】:

  • 我认为问题在于我必须加载 RVM 环境,我正在尝试使用 'source /usr/local/rvm/environments/ruby-2.0.0-p353@global' 但它还是不行

标签: ruby-on-rails ubuntu sidekiq upstart


【解决方案1】:

你说得对,需要加载 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

.....    
.....

有效吗?

【讨论】:

  • 我试过了,但在日志中出现以下错误:/bin/bash: line 10: exec: sidekiq: not found
  • 它工作我不得不将环境更改为源 /usr/local/rvm/environments/ruby-2.0.0-p353 (没有@global 部分),谢谢你的帮助:)
  • Sidekiq 需要 rvm 环境。以下是有关如何将 sidekiq 作为 usptart 运行的完整脚本和方法的链接。 jee-appy.blogspot.com/2016/02/…
  • @AjeetKhan,因为在 Ubuntu 16 之后新贵的工作正在被 systemd 取代。请更新以 rvm 作为源的新版本的文章。
猜你喜欢
  • 2012-09-26
  • 2014-08-23
  • 1970-01-01
  • 2011-11-07
  • 2014-10-27
  • 1970-01-01
  • 1970-01-01
  • 2014-10-10
  • 1970-01-01
相关资源
最近更新 更多