There are a few different stopgaps you might consider implementing to automatically restart an app after it crashes.
- One lightweight method that is framework-agnostic is to just wrap your service definitions in a bash
while loop. Your Procfile might look like:
web: while true; do bundle exec rails server; sleep 1; done
web: while true; do node app.js; sleep 1; done
- If you’re using Rails, you might consider a process monitoring tool like God to start your Rails server, instead of starting it directly. For example, if you’re running
bundle exec rails server to launch your server, you could use the following
god.rb (committed to the top level of your repo):
God.watch do |w|
w.name = 'rails'
w.start = 'bundle exec rails server'
Your Procfile would be:
- A similar approach for Node apps is to use the
forever package, and including the following line in your Procfile: