Skip to content

Instantly share code, notes, and snippets.

@KieranHayes
Created April 25, 2014 13:12
Show Gist options
  • Save KieranHayes/11289097 to your computer and use it in GitHub Desktop.
Save KieranHayes/11289097 to your computer and use it in GitHub Desktop.
#!/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/bin/bundle
bundle_exec_thin ()
{
for CONFIG_FILE in `ls -d /etc/thin/*`; do
SITE_DIR=`awk '/^chdir:/ { print $2; }' $CONFIG_FILE`
RAILS_ENV=`awk '/^environment:/ { print $2; }' $CONFIG_FILE`
cd $SITE_DIR
echo $CONFIG_FILE
echo $RAILS_ENV
RAILS_ENV=$RAILS_ENV $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