Skip to content

Instantly share code, notes, and snippets.

@zealot128
Created August 13, 2012 21:15
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zealot128/3344162 to your computer and use it in GitHub Desktop.
Save zealot128/3344162 to your computer and use it in GitHub Desktop.
Debian startup file for Rails thin instances

Rails startup with bundler, rvm and specific user

e.g. for user stefan, starting two different applications, located under /apps/APPLICATION/prod/current.

This script is very useful, because it is run at startup of server, so no 503 anymore.

Put this script under /etc/init.d/ and make it executable chmod +x /etc/init.d/rails_apps

#!/bin/bash
### BEGIN INIT INFO
# Provides: rails
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: rails applications
# Description: rails applications
### END INIT INFO
# Author: Name <email@domain.tld>
user="stefan"
railsstart() {
load_rvm="source /home/$user/.rvm/scripts/rvm && rvm use"
thin="bundle exec thin -C config/thin.yml"
path=$1
command=$2
echo "$load_rvm && cd /apps/$path/prod/current && $thin $command"
}
# Aktionen
case "$1" in
start)
exec sudo -u $user bash -c "`railsstart movie start`; `railsstart pics start`"
;;
stop)
exec sudo -u $user bash -c "`railsstart movie stop`; `railsstart pics stop`"
;;
restart)
exec sudo -u $user bash -c "`railsstart movie restart`; `railsstart pics restart`"
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment