Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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