Skip to content

Instantly share code, notes, and snippets.

@nogara
Forked from sbeam/thin.sh
Created February 20, 2017 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nogara/5557b78bc0f8c98f137d20bdf1b6a9f6 to your computer and use it in GitHub Desktop.
Save nogara/5557b78bc0f8c98f137d20bdf1b6a9f6 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 `ls -1 $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