Skip to content

Instantly share code, notes, and snippets.

@asux
Created October 2, 2012 15:24
Show Gist options
  • Save asux/3820099 to your computer and use it in GitHub Desktop.
Save asux/3820099 to your computer and use it in GitHub Desktop.
rvm and bundler aware thin initscript for Gentoo
#!/sbin/runscript
### 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
description="Thin is a fast and lightweight Rack application server."
description_restart_directly="Restart Thin server directly using 'restart' command. This not stopping and starting daemon."
extra_started_commands="restart_directly"
bundle_exec_thin () {
for CONFIG_FILE in ${CONFIG_PATH}/*.yml; do
SITE_DIR=`awk '/^chdir:/ { print $2; }' ${CONFIG_FILE}`
[ ! -z ${VERBOSE} ] && echo -e "Processing app in \e[1;32m${SITE_DIR}\e[m"
su ${SERVER_USER} -c "source /etc/profile.d/rvm.sh && cd ${SITE_DIR} && ${BUNDLE_CMD} exec thin $1 -C ${CONFIG_FILE} -q"
done
}
start() {
ebegin "Starting Thin rack-server"
bundle_exec_thin start
eend $?
}
stop() {
ebegin "Stopping Thin rack-server"
bundle_exec_thin stop
eend $?
}
restart_directly() {
ebegin "Restarting Thin rack-server"
bundle_exec_thin restart
eend $?
}
# vim: ts=4 ft=sh
# Thin configuration file - /etc/conf.d/thin
CONFIG_PATH=/etc/thin
BUNDLE_CMD="bundle"
SERVER_USER="git"
VERBOSE=""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment