Automatically start rails server with upstart

The following is how to set up an Upstart file so you can have a rails application autostart upon the startup of a server.

Modify the “USERNAME” and “TAG_FOR_THIS_PROCESS_IN_SYSLOG” fields to something that you want. It will run the server as the user you declare, so that the server isn’t run as the root user

If the process dies for any reason, Upstart will try to get it back up and running.

  description ""
  author ""

  # When to start the service
  start on runlevel [2345]

  # When to stop the service
  stop on runlevel [016]

  # Automatically restart process if crashed
  respawn

  # Start the process
  env RAILS_ENV=staging

  chdir /home/USERNAME/learn_sorcery

  exec su -c '/home/USERNAME/.rbenv/shims/bundle exec rails s | logger -t TAG_FOR_THIS_PROCESS_IN_SYSLOG' USERNAME

Leave a Reply