2014-11-17 108 views
0

我需要Sidekiq在我們的暫存應用程序上啓動服務器後運行。我們轉移到Rackspace上的其他服務器實例以更好地反映我們的生產條件。如下所示Sidekiq未在Rails 4.1.6啓動客運服務器時運行應用程序

在應用程序啓動與

passenger start --nginx-config-template nginx.conf.erb --address 127.0.0.1 -p 3002 --daemonize 

的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" 
# no "start on", we don't want to automatically start 
stop on (stopping workers or runlevel [06]) 
# change to match your deployment user 
setuid root 
setgid root 
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 
instance $index 
script 
# this script runs in /bin/sh by default 
# respawn as bash so we can source in rbenv 
exec /bin/bash <<EOT 
# use syslog for logging 
exec &> /dev/kmsg 
# pull in system rbenv 
export HOME=/root 
source /etc/profile.d/rbenv.sh 
cd /srv/monolith 
exec bin/sidekiq -i ${index} -e staging 
EOT 
end script 

和workers.conf

# /etc/init/workers.conf - manage a set of Sidekiqs 
# 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 sidekiq.conf for how to manage a single Sidekiq instance. 
# 
# Use "stop workers" to stop all Sidekiq instances. 
# Use "start workers" to start all instances. 
# Use "restart workers" to restart all instances. 
# Crazy, right? 
# 
description "manages the set of sidekiq processes" 
# This starts upon bootup and stops on shutdown 
start on runlevel [2345] 
stop on runlevel [06] 
# Set this to the number of Sidekiq processes you want 
# to run on this machine 
env NUM_WORKERS=2 
pre-start script 
for i in `seq 0 $((${NUM_WORKERS} - 1))` 
do 
start sidekiq index=$i 
done 
end script 

當我進入服務器並嘗試service sidekiq start index=0service sidekiq status index=0,它找不到該服務,但如果我運行bundle exec sidekiq -e staging,sidekiq啓動並在作業隊列中順利運行。不幸的是,一旦我關閉了ssh會話,sidekiq就找到了一種殺死自己的方法。

如何確保sidekiq在我啓動服務器時運行,並且如果出現問題,如使用upstart運行sidekiq時提到的,它將自動重啓?

謝謝。

回答

0

爲了運行Sidekiq,你應該把劇本叫 「sidekiq」 在

的/etc/init.d

一個服務,而不是在/ etc /初始化

相關問題