Created
August 24, 2012 19:08
-
-
Save sbeam/3454488 to your computer and use it in GitHub Desktop.
/etc/init.d/thin - replacement that runs bundle exec thin within each site
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 | |
### 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: S 0 1 6 | |
# Short-Description: thin initscript | |
# Description: thin | |
### END INIT INFO | |
## instead of using the installed script at /usr/local/ruby/bin/thin which | |
## fires up thin without bundler, this will cd into each site found in | |
## /etc/thin and run 'bundle exec thin'. Not pretty, but it is necessary to | |
## launch thin with bundler to avoid gem versioning conflicts | |
SCRIPT_NAME=/etc/init.d/thin | |
CONFIG_PATH=/etc/thin | |
BUNDLE_CMD=/usr/local/ruby/bin/bundle | |
bundle_exec_thin () | |
{ | |
for CONFIG_FILE in "$CONFIG_PATH/*.yml"; do | |
SITE_DIR=`awk '/^chdir:/ { print $2; }' $CONFIG_FILE` | |
cd $SITE_DIR | |
$BUNDLE_CMD exec thin $1 -C $CONFIG_FILE | |
done | |
} | |
case "$1" in | |
start) | |
bundle_exec_thin start | |
;; | |
stop) | |
bundle_exec_thin stop | |
;; | |
restart) | |
bundle_exec_thin restart | |
;; | |
*) | |
echo "Usage: $SCRIPT_NAME {start|stop|restart}" >&2 | |
exit 3 | |
;; | |
esac | |
: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Saw your post about the bundler conflicts. This little script is fantastic. Thanks for sharing!!