Skip to content

Instantly share code, notes, and snippets.

@jhollinger
Forked from sorah/thin
Created November 4, 2012 14:51
Show Gist options
  • Save jhollinger/4012178 to your computer and use it in GitHub Desktop.
Save jhollinger/4012178 to your computer and use it in GitHub Desktop.
/etc/init.d/thin - thin init script with bundle exec
#!/bin/bash
DAEMON=/usr/local/bin/thin
BUNDLE=/usr/local/bin/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"
user=`grep "^user: " $conf|sed -e 's/^user: //g'`
group=`grep "^group: " $conf|sed -e 's/^group: //g'`
# Switch to the app's directory and set permissions
cd `grep "^chdir: " $conf|sed -e 's/^chdir: //g'`
[ -d ./log ] && chown $user:$group ./log
[ -d ./tmp ] && chown -R $user:$group ./tmp
# Run with bundler
if [ -e Gemfile ] && grep thin Gemfile > /dev/null; then
$BUNDLE exec $DAEMON $1 -d --config=$conf
# Run with system Thin
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