Skip to content

Instantly share code, notes, and snippets.

@deathbob
Forked from kurbmedia/deploy.rb
Created November 8, 2010 16:05
Show Gist options
  • Save deathbob/667854 to your computer and use it in GitHub Desktop.
Save deathbob/667854 to your computer and use it in GitHub Desktop.
namespace :deploy do
# To avoid having to add a password for sudo, visudo and add
# deployusername ALL=(ALL) NOPASSWD: /etc/init.d/unicorn reload
task :start do
sudo "/etc/init.d/unicorn start"
end
task :stop do
sudo "/etc/init.d/unicorn stop"
end
task :restart do
sudo "/etc/init.d/unicorn reload"
end
end
upstream unicorn {
# fail_timeout=0 means we always retry an upstream even if it failed
# to return a good HTTP response (in case the Unicorn master nukes a
# single worker for timing out).
# for UNIX domain socket setups:
server unix:/tmp/unicorn.socket fail_timeout=0;
}
server {
# Default site used
listen 80 default;
server_name somewebsite.com;
root /apps/my_app/current/public;
access_log /var/log/nginx/my_app.log;
rewrite_log on;
client_max_body_size 5m;
client_body_buffer_size 128k;
# try_files attempts to use files in public first. it is more efficient than
# running if statements each request (and is the preferred method from nginx docs)
# sets up unicorn as the fallback url so anything not found ends up there
try_files $uri/index.html $uri.html $uri @unicorn;
location @unicorn {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_pass http://unicorn;
}
}
user webmin webmin;
worker_processes 4;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
accept_mutex on;
}
http {
include /etc/nginx/mime.types;
access_log /var/log/nginx/access.log;
sendfile on;
tcp_nopush on; # off may be better for *some* Comet/long-poll stuff
tcp_nodelay off; # on may be better for some Comet/long-poll stuff
gzip on;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 500;
gzip_disable "MSIE [1-6]\.";
gzip_types text/plain text/html text/xml text/css text/comma-separated-values text/javascript application/x-javascript application/atom+xml;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
#! /bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the unicorn web server
# Description: starts unicorn
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/unicorn_rails
DAEMON_OPTS="-c /apps/my_site/current/config/unicorn.rb -E production -D"
NAME=unicorn_rails
DESC=unicorn_rails
PID=/apps/my_site/shared/pids/unicorn.pid
case "$1" in
start)
echo -n "Starting $DESC: "
$DAEMON $DAEMON_OPTS
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
kill -QUIT `cat $PID`
echo "$NAME."
;;
restart)
echo -n "Restarting $DESC: "
kill -QUIT `cat $PID`
sleep 1
$DAEMON $DAEMON_OPTS
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
kill -HUP `cat $PID`
echo "$NAME."
;;
*)
echo "Usage: $NAME {start|stop|restart|reload}" >&2
exit 1
;;
esac
exit 0
# As many as you want.
worker_processes 3
# Cus your more than likely using Capistrano
working_directory "/apps/my_site/current"
# Setup socket
listen "/tmp/unicorn.socket", :backlog => 64
# destroy workers after 30 seconds instead of 60 seconds (not sure why? everyone else was doing it)
timeout 30
# change as nesessary
user 'appuser', 'appusergroup'
shared_path = "/apps/my_site/shared"
pid "#{shared_path}/pids/unicorn.pid"
stderr_path "#{shared_path}/log/unicorn.stderr.log"
stdout_path "#{shared_path}/log/unicorn.stdout.log"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment