Skip to content

Instantly share code, notes, and snippets.

@riywo
Created April 17, 2012 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save riywo/2408821 to your computer and use it in GitHub Desktop.
Save riywo/2408821 to your computer and use it in GitHub Desktop.
unicorn with daemontools
#!/bin/bash
# mkdir /service/redmine-unicorn
# cd /service/redmine-unicorn
# mkdir env
# echo "production" > env/RAILS_ENV
# echo "/home/riywo/redmine" > env/RAILS_ROOT
# echo "/home/riywo/.rbenv" > env/RBENV_ROOT
# echo "riywo" > env/USER
exec 2>&1 \
envdir ./env \
sh -c '
PATH="$RBENV_ROOT/bin:$PATH"
eval "$(rbenv init -)"
cd $RAILS_ROOT
exec setuidgid $USER \
bundle exec unicorn_rails -c ./config/unicorn.conf.rb -E $RAILS_ENV
'
worker_processes 4
listen 8080, :tcp_nopush => true
timeout 30
pid File.expand_path("tmp/pids/unicorn.pid", ENV['RAILS_ROOT'])
stderr_path File.expand_path("log/unicorn.stderr.log", ENV['RAILS_ROOT'])
stdout_path File.expand_path("log/unicorn.stdout.log", ENV['RAILS_ROOT'])
preload_app true
GC.respond_to?(:copy_on_write_friendly=) and
GC.copy_on_write_friendly = true
before_fork do |server, worker|
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment