Creating a foreman role for Rubber
To create a new role in Rubber you need to add a rubber-#{role}.yml and deploy-#{role}.rb file.
In my case I needed to migrate my procfile to get Delayed Jobs executed by Foreman on EC2 (previously hosted on Heroku).
Checkout the code below:
deploy-foreman.rb
namespace :rubber do
namespace :foreman do
desc "Export the Procfile to Ubuntu's upstart scripts"
task :export, roles: :foreman do
run "cd #{current_path} && bundle exec foreman export upstart /etc/init -f ./Procfile -a foreman -u #{user} -l #{shared_path}/log"
end
desc "Start the application services"
task :start, roles: :foreman do
sudo "service foreman start"
end
desc "Stop the application services"
task :stop, roles: :foreman do
sudo "service foreman stop"
end
desc "Restart the application services"
task :restart, roles: :foreman do
run "service foreman start || service foreman restart"
end
end
end
# Export foreman scripts
after "deploy:update", "rubber:foreman:export"
# Restart application scripts
before "deploy:restart", "rubber:foreman:restart"
# Restart application scripts
after "deploy:stop", "rubber:foreman:stop"
Optionally you could pass a -c parameter to the bundle exec command to run a specific foreman process and the number of instances to start.
-c worker=1
rubber-foreman.yml
gems: [foreman]
Written by Gabriel Cebrian
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#