-
-
Save jesperronn/2926435 to your computer and use it in GitHub Desktop.
unicorn startup/management script (to work from capistrano)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ------------------------------------------------------------------------------ | |
# Sample rails 3 config | |
# ------------------------------------------------------------------------------ | |
# Set your full path to application. | |
app_path = "/srv/www/xxx/current" | |
# Set unicorn options | |
worker_processes 2 | |
preload_app true | |
#timeout 30 | |
listen 3000 #listen to port 3000 for all interfaces (iptables will forward from port 80) | |
# Spawn unicorn master worker for user apps (group: apps) | |
user 'xxx', 'users' | |
# Fill path to your app | |
working_directory app_path | |
# Should be 'production' by default, otherwise use other env | |
rails_env = ENV['RAILS_ENV'] || 'production' | |
# Log everything to one file | |
stderr_path "log/unicorn.log" | |
stdout_path "log/unicorn.log" | |
# Set master PID location | |
pid_path = "#{app_path}/tmp/pids/unicorn.pid" | |
pid pid_path | |
before_fork do |server, worker| | |
ActiveRecord::Base.connection.disconnect! if defined?(ActiveRecord::Base) | |
##ENsure you do not point to an old capistrano release | |
ENV['BUNDLE_GEMFILE'] = File.join(app_path, "Gemfile") | |
old_pid_file = "#{pid_path}.oldbin" | |
old_pid = File.exists?(old_pid_file) && File.read(old_pid_file).to_i | |
if old_pid && server.pid != old_pid | |
puts "Killing old unicorn with PID #{old_pid}..." | |
begin | |
Process.kill("QUIT", old_pid) | |
rescue Errno::ENOENT, Errno::ESRCH | |
# someone else did our job for us | |
end | |
end | |
end | |
after_fork do |server, worker| | |
ActiveRecord::Base.establish_connection if defined?(ActiveRecord::Base) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment