Skip to content

Instantly share code, notes, and snippets.

@sbeam
Created August 24, 2012 19:08
Show Gist options
  • Save sbeam/3454488 to your computer and use it in GitHub Desktop.
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
#!/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
:
@kgodard
Copy link

kgodard commented Apr 9, 2015

Saw your post about the bundler conflicts. This little script is fantastic. Thanks for sharing!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment