Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nebirhos/bc6c374cdee98b84bc65 to your computer and use it in GitHub Desktop.
Save nebirhos/bc6c374cdee98b84bc65 to your computer and use it in GitHub Desktop.
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