Skip to content

Instantly share code, notes, and snippets.

@ryantownsend
Last active December 21, 2015 01:48
Show Gist options
  • Select an option

  • Save ryantownsend/6230000 to your computer and use it in GitHub Desktop.

Select an option

Save ryantownsend/6230000 to your computer and use it in GitHub Desktop.
namespace :foreman do
desc "Export the Procfile to Ubuntu's upstart scripts"
task :export do
options = {
:app => fetch(:application),
:log => shared_path.join("log"),
:user => fetch(:user)
}
roles(:app).each do |server|
on(server) do
option_string = options.map { |k,v| "--#{k}=#{v}" }.join(" ")
execute "cd #{release_path} && sudo `which bundle` exec foreman export upstart /etc/init #{option_string}"
end
end
end
desc "Start the application"
task :start do
on roles(:app) do
execute "sudo start #{fetch(:application)}"
end
end
desc "Stop the application"
task :stop do
on roles(:app) do
execute "sudo stop #{fetch(:application)} 2>/dev/null; echo ''"
end
end
desc "Restart the application"
task :restart do
on roles(:app) do
execute "sudo restart #{fetch(:application)}"
end
end
after "deploy:bundle", "foreman:export"
end
# ...
http {
upstream appserver {
server unix:///path/to/shared/tmp/sockets/puma.sock;
}
server {
# ssl only
listen 443 ssl default deferred;
# set the domain
server_name DOMAIN_NAME;
# ...
# location of our static files
root /path/to/current/public;
# attempt to find the file, if not, serve via puma
try_files $uri @app;
location @app {
# if the maintenance page exists, throw a 503 error
if (-f $document_root/system/maintenance.html) {
return 503;
break;
}
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://appserver;
}
}
}
web: bundle exec puma -t 2:8 -C /path/to/current/config/puma.rb -b unix:///path/to/shared/tmp/sockets/puma.sock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment