Skip to content

Instantly share code, notes, and snippets.

@ulfurinn
Created August 24, 2012 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ulfurinn/3448238 to your computer and use it in GitHub Desktop.
Save ulfurinn/3448238 to your computer and use it in GitHub Desktop.
thin init.d script supporting individual servers
#!/bin/bash
### BEGIN INIT INFO
# Provides: thin
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: thin initscript
# Description: thin
### END INIT INFO
# Original author: Forrest Robertson
# Do NOT "set -e"
DAEMON=/usr/local/bin/thin
BUNDLE_DAEMON=/usr/local/bin/bundle
SCRIPT_NAME=/etc/init.d/thin
CONFIG_PATH=/etc/thin
HOME=/var/www
export HOME
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
function run_command {
command=$1
config=$2
dir=`grep chdir ${config} |cut -d ' ' -f 2`
if [ -f $dir/Gemfile ]
then
cur=`pwd`
cd $dir
$BUNDLE_DAEMON exec $DAEMON -C $config $command
cd $cur
else
$DAEMON -C $config $command
fi
}
case "$1" in
start)
COMMAND=start
;;
stop)
COMMAND=stop
;;
restart)
COMMAND=restart
;;
*)
echo "Usage: $SCRIPT_NAME {start|stop|restart} [server]" >&2
exit 3
;;
esac
case "$2" in
"")
for i in $CONFIG_PATH/*
do
run_command $COMMAND $i
done
;;
*)
FILE="$CONFIG_PATH/$2.yml"
if [ -f $FILE ]
then
run_command $COMMAND $FILE
else
echo "Expecting config file $FILE but it does not exist" >&2
exit 3
fi
;;
esac
:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment