Created
November 25, 2015 11:58
-
-
Save illucent/723c7956517eef83be0a to your computer and use it in GitHub Desktop.
This file contains hidden or 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/sh | |
| ### 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 | |
| # Original author: Forrest Robertson | |
| # Do NOT "set -e" | |
| DAEMON=/usr/local/rbenv/shims/thin | |
| SCRIPT_NAME=/etc/init.d/thin | |
| CONFIG_PATH=/etc/thin | |
| BUNDLE=/usr/local/rbenv/shims/bundle | |
| if [ "$1" != "start" -a "$1" != "stop" -a "$1" != "restart" ]; then | |
| echo "Usage: $0 {start|stop|restart}" | |
| exit 1 | |
| fi | |
| for config_file in $CONFIG_PATH/* | |
| do | |
| cat $config_file | grep "^daemonize: true" > /dev/null | |
| if [ $? = 1 ]; then | |
| echo $config_file must contain daemonize: true | |
| exit 1 | |
| fi | |
| site_path=`cat $config_file | grep chdir | awk '{ print $2 }'` | |
| exec_cmd=$DAEMON | |
| bundler_str="" | |
| if [ -f $site_path/Gemfile ]; then | |
| exec_cmd="$BUNDLE exec thin" | |
| bundler_str=" (with bundler)" | |
| fi | |
| case "$1" in | |
| start) | |
| echo "Starting thin$bundler_str with $config_file" | |
| (cd $site_path && $exec_cmd start -C $config_file > /dev/null) | |
| if [ $? = 0 ]; then | |
| exit 0 | |
| else | |
| exit 1 | |
| fi | |
| ;; | |
| stop) | |
| echo "Stopping thin$bundler_str with $config_file" | |
| (cd $site_path && $exec_cmd stop -C $config_file > /dev/null) | |
| if [ $? = 0 ]; then | |
| exit 0 | |
| else | |
| exit 1 | |
| fi | |
| ;; | |
| restart) | |
| echo "Restarting thin$bundler_str with $config_file" | |
| (cd $site_path && $exec_cmd restart -C $config_file > /dev/null) | |
| if [ $? = 0 ]; then | |
| exit 0 | |
| else | |
| exit 1 | |
| fi | |
| ;; | |
| esac | |
| done | |
| #case "$1" in | |
| # start) | |
| # $DAEMON start --all $CONFIG_PATH | |
| # ;; | |
| # stop) | |
| # $DAEMON stop --all $CONFIG_PATH | |
| # ;; | |
| # restart) | |
| # $DAEMON restart --all $CONFIG_PATH | |
| # ;; | |
| # *) | |
| # echo "Usage: $SCRIPT_NAME {start|stop|restart}" >&2 | |
| # exit 3 | |
| # ;; | |
| #esac | |
This file contains hidden or 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 | |
| . /etc/rc.conf | |
| . /etc/rc.d/functions | |
| DAEMON=/usr/bin/thin | |
| SCRIPT_NAME=/etc/rc.d/thin | |
| CONFIG_PATH=/etc/thin | |
| BUNDLE=/usr/bin/bundle | |
| # Exit if the package is not installed | |
| [ -x "$DAEMON" ] || exit 0 | |
| if [ "$1" != "start" -a "$1" != "stop" -a "$1" != "restart" ]; then | |
| echo "Usage: $0 {start|stop|restart}" | |
| exit 1 | |
| fi | |
| for config_file in $CONFIG_PATH/* | |
| do | |
| cat $config_file | grep "^daemonize: true" > /dev/null | |
| if [ $? = 1 ]; then | |
| echo $config_file must contain daemonize: true | |
| stat_fail | |
| exit 1 | |
| fi | |
| site_path=`cat $config_file | grep chdir | awk '{ print $2 }'` | |
| exec_cmd=$DAEMON | |
| bundler_str="" | |
| if [ -f $site_path/Gemfile ]; then | |
| exec_cmd="$BUNDLE exec thin" | |
| bundler_str=" (with bundler)" | |
| fi | |
| case "$1" in | |
| start) | |
| stat_busy "Starting thin$bundler_str with $config_file" | |
| (cd $site_path && $exec_cmd start -C $config_file > /dev/null) | |
| if [ $? = 0 ]; then | |
| stat_done | |
| else | |
| stat_fail | |
| exit 1 | |
| fi | |
| ;; | |
| stop) | |
| stat_busy "Stopping thin$bundler_str with $config_file" | |
| (cd $site_path && $exec_cmd stop -C $config_file > /dev/null) | |
| if [ $? = 0 ]; then | |
| stat_done | |
| else | |
| stat_fail | |
| exit 1 | |
| fi | |
| ;; | |
| restart) | |
| stat_busy "Restarting thin$bundler_str with $config_file" | |
| (cd $site_path && $exec_cmd restart -C $config_file > /dev/null) | |
| if [ $? = 0 ]; then | |
| stat_done | |
| else | |
| stat_fail | |
| exit 1 | |
| fi | |
| ;; | |
| esac | |
| done | |
| #case "$1" in | |
| # start) | |
| # $DAEMON start --all $CONFIG_PATH | |
| # ;; | |
| # stop) | |
| # $DAEMON stop --all $CONFIG_PATH | |
| # ;; | |
| # restart) | |
| # $DAEMON restart --all $CONFIG_PATH | |
| # ;; | |
| # *) | |
| # 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