From e855144da8d74dbbdfd83a2bd5affbb44066d2ef Mon Sep 17 00:00:00 2001 From: Snow Helsing Date: Sun, 7 Feb 2016 22:16:34 +0800 Subject: [PATCH 1/4] CHG: provide both hot and phased restart in jungle script --- tools/jungle/init.d/puma | 62 +++++++++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 7 deletions(-) diff --git a/tools/jungle/init.d/puma b/tools/jungle/init.d/puma index 446c7102..8c9bec7d 100755 --- a/tools/jungle/init.d/puma +++ b/tools/jungle/init.d/puma @@ -137,15 +137,49 @@ do_restart_one() { PIDFILE=$1/tmp/puma/pid i=`grep $1 $CONFIG` dir=`echo $i | cut -d , -f 1` - + if [ -e $PIDFILE ]; then log_daemon_msg "--> About to restart puma $1" - if [ "$USE_LOCAL_BUNDLE" -eq 1 ]; then - cd $1 && bundle exec pumactl --state $dir/tmp/puma/state restart - else - pumactl --state $dir/tmp/puma/state restart + kill -s USR2 `cat $PIDFILE` + # TODO Check if process exist + else + log_daemon_msg "--> Your puma was never playing... Let's get it out there first" + user=`echo $i | cut -d , -f 2` + config_file=`echo $i | cut -d , -f 3` + if [ "$config_file" = "" ]; then + config_file="$dir/config/puma.rb" fi - # kill -s USR2 `cat $PIDFILE` + log_file=`echo $i | cut -d , -f 4` + if [ "$log_file" = "" ]; then + log_file="$dir/log/puma.log" + fi + environment=`echo $i | cut -d , -f 5` + do_start_one $dir $user $config_file $log_file $environment + fi + return 0 +} + +# +# Function that phased restarts the jungle +# +do_phased_restart() { + for i in $JUNGLE; do + dir=`echo $i | cut -d , -f 1` + do_restart_one $dir + done +} + +# +# Function that sends a SIGUSR1 to the daemon/service +# +do_phased_restart_one() { + PIDFILE=$1/tmp/puma/pid + i=`grep $1 $CONFIG` + dir=`echo $i | cut -d , -f 1` + + if [ -e $PIDFILE ]; then + log_daemon_msg "--> About to restart puma $1" + kill -s USR1 `cat $PIDFILE` # TODO Check if process exist else log_daemon_msg "--> Your puma was never playing... Let's get it out there first" @@ -355,6 +389,20 @@ case "$1" in 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; esac ;; + phased-restart) + log_daemon_msg "Restarting (phased) $DESC" "$NAME" + if [ "$#" -eq 1 ]; then + do_phased_restart + else + i=`grep $2 $CONFIG` + dir=`echo $i | cut -d , -f 1` + do_phased_restart_one $dir + fi + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; add) if [ "$#" -lt 3 ]; then echo "Please, specifiy the app's directory and the user that will run it at least." @@ -383,7 +431,7 @@ case "$1" in ;; *) echo "Usage:" >&2 - echo " Run the jungle: $SCRIPTNAME {start|stop|status|restart}" >&2 + echo " Run the jungle: $SCRIPTNAME {start|stop|status|restart|phased-restart}" >&2 echo " Add a Puma: $SCRIPTNAME add /path/to/app user /path/to/app/config/puma.rb /path/to/app/config/log/puma.log" echo " config and log are optionals." echo " Remove a Puma: $SCRIPTNAME remove /path/to/app" From 73333b602576dd9113f10e701a79d864a2c0082f Mon Sep 17 00:00:00 2001 From: Snow Helsing Date: Mon, 28 Mar 2016 11:13:15 +0800 Subject: [PATCH 2/4] CHG: init rbenv in run-puma --- tools/jungle/init.d/run-puma | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/jungle/init.d/run-puma b/tools/jungle/init.d/run-puma index 059d177e..1c169d40 100755 --- a/tools/jungle/init.d/run-puma +++ b/tools/jungle/init.d/run-puma @@ -1,3 +1,14 @@ #!/bin/bash + +# on system boot, and root have no rbenv installed, +# after start-stop-daemon switched to current user, we have to init rbenv +if [ -d "$HOME/.rbenv/bin" ]; then + PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH" + eval "$(rbenv init -)" +elif [ -d "/usr/local/rbenv/bin" ]; then + PATH="/usr/local/rbenv/bin:/usr/local/rbenv/shims:$PATH" + eval "$(rbenv init -)" +fi + app=$1; config=$2; log=$3; cd $app && exec bundle exec puma -C $config 2>&1 >> $log From 17673bab200db3be68e4a5aec06d2907fc2d11b8 Mon Sep 17 00:00:00 2001 From: Snow Helsing Date: Sun, 7 Feb 2016 22:16:34 +0800 Subject: [PATCH 3/4] FIX: typo --- tools/jungle/init.d/puma | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/jungle/init.d/puma b/tools/jungle/init.d/puma index 8c9bec7d..978e7bcb 100755 --- a/tools/jungle/init.d/puma +++ b/tools/jungle/init.d/puma @@ -165,7 +165,7 @@ do_restart_one() { do_phased_restart() { for i in $JUNGLE; do dir=`echo $i | cut -d , -f 1` - do_restart_one $dir + do_phased_restart_one $dir done } From b7161cd9e5d128d3ba438e7b1785d4335a6b147d Mon Sep 17 00:00:00 2001 From: Snow Helsing Date: Tue, 3 May 2016 15:40:03 +0800 Subject: [PATCH 4/4] ENH: detection of rbenv path --- tools/jungle/init.d/puma | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/jungle/init.d/puma b/tools/jungle/init.d/puma index 978e7bcb..2eb5ec03 100755 --- a/tools/jungle/init.d/puma +++ b/tools/jungle/init.d/puma @@ -290,16 +290,25 @@ do_remove() { config_bundler() { HOME="$(eval echo ~$(id -un))" - if [ -d "/usr/local/rbenv/bin" ]; then + + if [ -d "$1/.rbenv/bin" ]; then + PATH="$1/.rbenv/bin:$1/.rbenv/shims:$1" + eval "$(rbenv init -)" + USE_LOCAL_BUNDLE=1 + return 0 + + elif [ -d "/usr/local/rbenv/bin" ]; then PATH="/usr/local/rbenv/bin:/usr/local/rbenv/shims:$PATH" eval "$(rbenv init -)" USE_LOCAL_BUNDLE=1 return 0 + elif [ -d "$HOME/.rbenv/bin" ]; then PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH" eval "$(rbenv init -)" USE_LOCAL_BUNDLE=1 return 0 + # TODO: test rvm # elif [ -f /etc/profile.d/rvm.sh ]; then # source /etc/profile.d/rvm.sh