-
-
Save jhollinger/4012178 to your computer and use it in GitHub Desktop.
/etc/init.d/thin - thin init script with bundle exec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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