# This example config should work with Ubuntu 12.04+.  It
# allows you to manage Sidekiq instances with
# Upstart, Ubuntu's native service management tool.
#
# NOTE: This is heavily inspired by Sidekiq's example sidekiq.conf
#
# Save this config as /etc/init/sidekiq-APPNAME.conf then mange sidekiq with:
#   sudo start sidekiq-APPNAME
#   sudo stop sidekiq-APPNAME
#   sudo status sidekiq-APPNAME
#
# or use the service command:
#   sudo service sidekiq-APPNAME {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 deploy
setgid deploy

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
exec /bin/bash <<EOT
  exec "cd #{@release_path} ; nohup bundle exec sidekiq -e #{@sidekiq_env} -C #{@release_path}/config/sidekiq.yml -P #{@release_path}/tmp/pids/sidekiq.pid >> /dev/null 2>&1 &"
EOT
end script

pre-stop script
exec /bin/bash <<EOT
  exec "cd #{@release_path} && if [ -f #{@release_path}/tmp/pids/sidekiq.pid ]; then bundle exec sidekiqctl stop #{@release_path}/tmp/pids/sidekiq.pid 60 ; fi"
EOT
end script

# This example config should work with Ubuntu 12.04+.  It
# allows you to manage Sidekiq instances with
# Upstart, Ubuntu's native service management tool.
#
# NOTE: This is heavily inspired by Sidekiq's example sidekiq.conf
#
# Save this config as /etc/init/sidekiq-APPNAME.conf then mange sidekiq with:
#   sudo start sidekiq-APPNAME
#   sudo stop sidekiq-APPNAME
#   sudo status sidekiq-APPNAME
#
# or use the service command:
#   sudo service sidekiq-APPNAME {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 deploy
setgid www-data

respawn
respawn limit 3 30

# 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

chdir "<%= @release_path %>"

script
  exec bundle exec sidekiq -e <%= @sidekiq_env %> -C config/sidekiq.yml
end script

Revert to old sidekiq upstart syntax
Revert to old sidekiq upstart syntax
