From 266540cec3678b5c87627b81eb452ab4cff5967d Mon Sep 17 00:00:00 2001 From: Krzysztof Wilczynski Date: Thu, 27 Nov 2014 15:57:47 +0000 Subject: [PATCH] Add the ability to pass environment variables to the init script (for Jungle). Signed-off-by: Krzysztof Wilczynski --- tools/jungle/init.d/puma | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/tools/jungle/init.d/puma b/tools/jungle/init.d/puma index 8bcee586..3d54a746 100755 --- a/tools/jungle/init.d/puma +++ b/tools/jungle/init.d/puma @@ -47,7 +47,8 @@ do_start() { if [ "$log_file" = "" ]; then log_file="$dir/log/puma.log" fi - do_start_one $dir $user $config_file $log_file + environment=`echo $i | cut -d , -f 5` + do_start_one $dir $user $config_file $log_file $environment done } @@ -57,12 +58,12 @@ do_start_one() { PID=`cat $PIDFILE` # If the puma isn't running, run it, otherwise restart it. if [ "`ps -A -o pid= | grep -c $PID`" -eq 0 ]; then - do_start_one_do $1 $2 $3 $4 + do_start_one_do $1 $2 $3 $4 $5 else do_restart_one $1 fi else - do_start_one_do $1 $2 $3 $4 + do_start_one_do $1 $2 $3 $4 $5 fi } @@ -70,6 +71,14 @@ do_start_one_do() { log_daemon_msg "--> Woke up puma $1" log_daemon_msg "user $2" log_daemon_msg "log to $4" + + if [ ! -z "$5" ]; then + for e in $(echo "$5" | tr ';' '\n'); do + log_daemon_msg "environment $e" + v=${e%%\=*} ; eval "$e" ; export $v + done + fi + start-stop-daemon --verbose --start --chdir $1 --chuid $2 --background --exec $RUNPUMA -- $1 $3 $4 } @@ -140,7 +149,8 @@ do_restart_one() { if [ "$log_file" = "" ]; then log_file="$dir/log/puma.log" fi - do_start_one $dir $user $config_file $log_file + environment=`echo $i | cut -d , -f 5` + do_start_one $dir $user $config_file $log_file $environment fi return 0 } @@ -209,6 +219,11 @@ do_add() { str="$str,$4" fi + # Environment variables + if [ "$5" != "" ]; then + str="$str,$5" + fi + # Add it to the jungle echo $str >> $CONFIG log_daemon_msg "Added a Puma to the jungle: $str. You still have to start it though."