以下是 sidekiq 的 upstart 脚本。运行 upstart
sudo service sidekiq start
得到以下错误
sidekiq: unrecognized service
以下是sidekiq.conf
内容
# Just a custom description for our Job
description "Sidekiq Background Worker"
# On which conditions the job should start. In this case it's very simple: On the system startup (this is basically when the system is booted)
#start on startup
start on runlevel [2345]
# On which conditions the job should stop. In this case when the system reboot (http://upstart.ubuntu.com/cookbook/#runlevels)
stop on runlevel [06]
# This are the User and User Group that will be used to run the Job. On our case it should be the user that we have set on our capistrano script for instance.
# You can check at `config/deploy/<environment>.rb` on this line `server <some_ip_addreess>, user: <deploy_user>`
setuid ubuntu
setgid ubuntu
# This indicate that we want to restart the Job if it crashes
respawn
respawn limit 3 30
# TERM is sent by sidekiqctl when stopping sidekiq. Without declaring these as normal exit codes, it just respawns.
normal exit 0 TERM
script
# this script runs in /bin/sh by default
# respawn as bash so we can source in RVM
exec /bin/bash <<EOT
# use syslog for logging
exec &> /dev/kmsg
# Jump into the capistrano deployment directory
cd /home/ubuntu/myproject/
# Start Sidekiq through RVM. Note that I'm using the standard Capistrano paths
exec ~/.rvm/bin/rvm-shell -c 'bundle exec sidekiq -C ./config/sidekiq.yml --environment production --logfile /home/ubuntu/myproject/log/sidekiq.log'
EOT
end script
没有显示任何日志syslog
。
答案1
您可以创建 upstart 文件的符号链接,从 /etc/init/sidekiq.conf 到 /etc/init.d/sidekiq,然后运行sudo service sidekiq start
。
调试 upstart 脚本的更好方法是放置前置和后置块,如此处所述http://upstart.ubuntu.com/getting-started.html。
以下是 sidekiq.conf 的示例https://github.com/mperham/sidekiq/blob/master/examples/upstart/sidekiq.conf。
将下面的代码放在执行部分,将所有输出和错误发送到文件。
exec 2> /tmp/rc.local.log # send stderr from this file to a log file
exec 1>&2 # send stdout to the same log file
set -x