Skip to content

Instantly share code, notes, and snippets.

@FredrikL
Created March 9, 2013 06:16
Show Gist options
  • Save FredrikL/5123062 to your computer and use it in GitHub Desktop.
Save FredrikL/5123062 to your computer and use it in GitHub Desktop.
#! /bin/sh
### BEGIN INIT INFO
# Provides: rails
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start a Rails instance
# Description: Do the simplest thing possible in keeping with
# upstart to spin up a single Rails instance.
### END INIT INFO
# Author: Sam Pointer & Fredrik Leijon
#
# Do NOT "set -e"
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/home/pi/.rvm/bin
USER="pi"
PORT=3000
RAILS_ROOT="/home/pi/dashboard"
COMMAND="rails s -d"
DESCRIPTION="Rails instance"
RVM_PROFILE="/home/pi/.rvm/environments/default"
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
su -c "source $RVM_PROFILE && cd $RAILS_ROOT && $COMMAND" $USER
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESCRIPTION"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment