Skip to content

Instantly share code, notes, and snippets.

@vdv
Last active August 29, 2015 14:06
Show Gist options
  • Save vdv/66f12ec44f49a730ff9f to your computer and use it in GitHub Desktop.
Save vdv/66f12ec44f49a730ff9f to your computer and use it in GitHub Desktop.
Ubuntu 12.04 Rails run scripts
upstream rails_app_upstream {
server unix:/home/deployer/projects/rails_app/shared/tmp/sockets/unicorn.socket fail_timeout=0;
}
server {
#listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6
server_name localhost my_server.ru;
root /home/deployer/projects/rails_app/current/public;
index index.html index.htm;
access_log /home/deployer/projects/rails_app/shared/log/nginx-access.log;
error_log /home/deployer/projects/rails_app/shared/log/nginx-error.log;
client_max_body_size 10m;
client_body_buffer_size 128k;
location / {
try_files $uri/index.html $uri.html $uri @rails_app;
}
location @rails_app{
proxy_pass http://rails_app_upstream;
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;
}
#location ~ ^/(images|javascripts|stylesheets|system|assets|ckeditor_assets)/ {
location ~* ".*?\.(ico|css|js|gif|jpg|jpeg|png|doc|pdf)(\?[0-9]*)?$" {
expires 24h;
#expires max;
proxy_cache_valid 200 302 60m;
proxy_cache_valid 404 1m;
break;
}
}
description "RailsApp DelatedJob"
start on runlevel [2]
stop on runlevel [016]
console log
setuid deployer
script
chdir /home/deployer/projects/rails_app/current
RAILS_ENV=production /home/deployer/.rbenv/shims/bundle exec /home/deployer/projects/rails_app/current/script/delayed_job start
end script
description "RailsApp Application"
start on runlevel [2345]
stop on runlevel [016]
console log
setuid deployer
script
cd /home/deployer/projects/rails_app/current && /home/deployer/.rbenv/shims/bundle exec unicorn_rails -c ./config/unicorn.conf.rb -E production
end script
description "RailsApp Application"
start on runlevel [2345]
stop on runlevel [016]
console log
setuid deployer
chdir /home/deployer/projects/rails_app/current
exec /home/deployer/projects/rails_app/current/rvm_wrapper unicorn_rails -c /home/deployer/projects/rails_app/current/config/unicorn/unicorn.rb -E production
respawn
#!/usr/bin/env bash
if [[ -s "/home/deployer/.rvm/environments/ruby-2.0.0-p247" ]]
then
source "/home/deployer/.rvm/environments/ruby-2.0.0-p247"
exec bundle exec "$@"
else
echo "ERROR: Missing RVM environment file: '/home/deployer/.rvm/environments/ruby-2.0.0-p247'" >&2
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment