Skip to content

Instantly share code, notes, and snippets.

@framallo
Created October 9, 2012 19:47
Show Gist options
  • Save framallo/3860997 to your computer and use it in GitHub Desktop.
Save framallo/3860997 to your computer and use it in GitHub Desktop.
init upstart script for ubuntu 12.04 and Rails 3 app
app_dir = "/home/public_forums/unstable/"
worker_processes 5
pid "#{app_dir}/tmp/pids/unicorn.pid"
# listen "#{app_dir}/tmp/sockets/public_forum.socket"
listen 5000, :tcp_nopush => true
stderr_path "#{app_dir}/log/unicorn.stderr.log"
stdout_path "#{app_dir}/log/unicorn.stdout.log"
before_fork do |server, worker|
# the following is highly recomended for Rails + "preload_app true"
# as there's no need for the master process to hold a connection
defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
# the following is *required* for Rails + "preload_app true",
defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
end
#!upstart
description "<some app> rails server"
start on (filesystem and net-device-up IFACE=lo)
stop on shutdown
setuid <production_user>
script
/bin/bash <<EOT
export RAILS_ENV=production
source /etc/profile
cd /home/canvas/canvas
source .rvmrc
rails server
EOT
end script
respawn
respawn limit 10 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment