Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Unicorn + Upstart + Capistrano 3
# ...
namespace :deploy do
desc 'Restart application (duplicate)'
task :restart do
invoke 'unicorn:restart'
end
after :publishing, :restart
end
# ...
# ...
before_fork do |server, worker|
f = File.open("#{server.config[:pid]}.lock", 'w')
exit unless f.flock(File::LOCK_SH)
end
# ...
description "Unicorn webserver control"
author "nebirhos <me@nebirhos.com>"
start on runlevel [2345]
stop on runlevel [016]
respawn
setuid username
setgid username
# points to your RBenv/RVM/whatever bin
env PATH=./bin:./bin/stubs:/opt/rbenv/shims:/opt/rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
env LOCKFILE_PATH=/myapp/current/tmp/pids/unicorn.pid.lock
env UNICORN_CONFIG_PATH=/myapp/current/current/config/unicorn.rb
env ENVIRONMENT=production
chdir /myapp/current
script
bundle exec unicorn -c $UNICORN_CONFIG_PATH -E $ENVIRONMENT
flock -x 0 < $LOCKFILE_PATH
end script
post-stop exec rm -f $LOCKFILE_PATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.