Skip to content

Instantly share code, notes, and snippets.

@uk-ar
Forked from sorah/thin
Created March 28, 2013 00:27
Show Gist options
  • Save uk-ar/5259462 to your computer and use it in GitHub Desktop.
Save uk-ar/5259462 to your computer and use it in GitHub Desktop.
#!/bin/bash
DAEMON=/path/to/thin
BUNDLE=/path/to/bundle
CONFIG_PATH=/etc/thin
SCRIPT_NAME=/etc/init.d/thin
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
invoke()
{
CONFIGS=$CONFIG_PATH/*
[ -e "$CONFIG_PATH/$2.yml" ] && CONFIGS=$CONFIG_PATH/$2.yml
for conf in $CONFIGS
do
echo "[$1] $conf"
cd `grep "^chdir: " $conf|sed -e 's/^chdir: //g'`
[ -d "./log" ] && chown `grep "^user: " $conf|sed -e 's/^user: //g'` ./log
chown -R `grep "^user: " $conf|sed -e 's/^user: //g'` ./tmp/pids
chgrp -R `grep "^group: " $conf|sed -e 's/^group: //g'` ./tmp/pids
if [ -e "Gemfile" ]; then
$BUNDLE exec $DAEMON $1 -d --config=$conf
else
$DAEMON $1 -d --config=$conf
fi
done
}
case "$1" in
start)
invoke start $2
;;
stop)
invoke stop $2
;;
restart)
invoke restart $2
;;
*)
echo "Usage: $SCRIPT_NAME {start|stop|restart} [config_name]" >&2
exit 3
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment