Skip to content

Instantly share code, notes, and snippets.

@attilahorvath
Created May 15, 2015 11:24
Show Gist options
  • Save attilahorvath/8634656bae76ea191b78 to your computer and use it in GitHub Desktop.
Save attilahorvath/8634656bae76ea191b78 to your computer and use it in GitHub Desktop.
Whenever tasks to automatically start web apps and background workers after a server reboot
# config/deploy.rb
# Using Capistrano 3
# Set the current environment for Whenever and avoid name collisions
set :whenever_environment, -> { fetch(:stage) }
set :whenever_identifier, -> { "#{fetch(:application)}_#{fetch(:stage)}" }
# config/schedule.rb
every "@reboot" do
# If the app is using Puma
command "cd #{path} && bundle exec puma -e #{@environment}"
# If the app is using Delayed Job
command "cd #{path} && RAILS_ENV=#{@environment} bundle exec delayed_job start"
# If the app is using Sidekiq
command "cd #{path} && RAILS_ENV=#{@environment} bundle exec sidekiq"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment