Skip to content

Instantly share code, notes, and snippets.

@cblunt
Last active November 26, 2016 22:57
Show Gist options
  • Save cblunt/5701286 to your computer and use it in GitHub Desktop.
Save cblunt/5701286 to your computer and use it in GitHub Desktop.
Rails app init.d script for passenger-standalone
#!/bin/bash
### BEGIN INIT INFO
# Provides: myapp passenger in standalone
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Interactive: true
# Short-Description: Start/stop myapp.com web site
### END INIT INFO
#PATH=/sbin:/usr/sbin:/bin:/usr/bin
PASSENGER="passenger"
ADDRESS=127.0.0.1
PORT=5000
ENVIRONMENT=production
APP_NAME=myapp
APP_DIR="/var/apps/$APP_NAME/current"
USER="chris"
SET_PATH="cd $APP_DIR"
PRE_CMD="" # e.g. "SENDGRID_USERNAME=username"
CMD="$SET_PATH; $PRE_CMD $PASSENGER start -a $ADDRESS -p $PORT -e $ENVIRONMENT -d"
. /lib/lsb/init-functions
case "$1" in
start)
echo "Starting $APP_NAME passenger"
echo "su - $USER -c \"$CMD\""
su - $USER -c "$CMD"
;;
stop)
echo "Stopping $APP_NAME passenger"
cd $APP_DIR
$PASSENGER stop -p $PORT
;;
restart)
echo "Restarting $APP_NAME passenger"
cd $APP_DIR
$PASSENGER stop -p $PORT
echo "su - $USER -c \"$CMD\""
su - $USER -c "$CMD"
;;
*)
echo "Usage: $0 start|stop" >&2
exit 3
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment