From 2f61580cdc94b287038ef4ba0700a214dde9c373 Mon Sep 17 00:00:00 2001 From: Cameron Johnston Date: Wed, 24 Aug 2016 11:42:41 -0600 Subject: [PATCH 1/9] adding sensu-service wrapper script --- sensu_configs/bin/sensu-service | 161 ++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100755 sensu_configs/bin/sensu-service diff --git a/sensu_configs/bin/sensu-service b/sensu_configs/bin/sensu-service new file mode 100755 index 0000000..b3279f2 --- /dev/null +++ b/sensu_configs/bin/sensu-service @@ -0,0 +1,161 @@ +#!/usr/bin/env bash + +action=$1 +sensu_service=sensu-$2 +forking=$3 + +CONFIG_FILE=/etc/sensu/config.json +CONFIG_DIR=/etc/sensu/conf.d +EXTENSION_DIR=/etc/sensu/extensions +PLUGINS_DIR=/etc/sensu/plugins +HANDLERS_DIR=/etc/sensu/handlers +LOG_DIR=/var/log/sensu +LOG_LEVEL=info +PID_DIR=/var/run/sensu +USER=sensu +SERVICE_MAX_WAIT=10 + +if [ -f /etc/default/sensu ]; then + . /etc/default/sensu +fi + +cd /opt/sensu + +svc_exec="/opt/sensu/bin/$sensu_service" + +logfile=$LOG_DIR/$sensu_service.log +pidfile=$PID_DIR/$sensu_service.pid +options="-c $CONFIG_FILE -d $CONFIG_DIR -e $EXTENSION_DIR -p $pidfile -l $logfile -L $LOG_LEVEL $OPTIONS" + +if [ "x$forking" = "xfork" ]; then + options="-b $options" +fi + +ensure_dir() { + if [ ! -d $1 ]; then + mkdir -p $1 + chown -R $2 $1 + chmod 755 $1 + fi +} + +set_sensu_paths() { + if [ "x$EMBEDDED_RUBY" = "xtrue" ]; then + export PATH=/opt/sensu/embedded/bin:$PATH:$PLUGINS_DIR:$HANDLERS_DIR + export GEM_PATH=/opt/sensu/embedded/lib/ruby/gems/2.3.0:$GEM_PATH + else + export PATH=$PATH:$PLUGINS_DIR:$HANDLERS_DIR + fi +} + +echo_ok() { + echo_success; echo +} +echo_fail() { + echo_failure; echo +} +log_success_msg() { + success $"$@" +} +log_failure_msg() { + failure $"$@" + echo $"$@" +} +log_action_msg() { + echo $@ +} + +pid_pgrep() { + pgrep -f -P 1 -u $USER " $svc_exec " +} + +validate_config() { + validate_options="--validate_config -b -c $CONFIG_FILE -d $CONFIG_DIR -e $EXTENSION_DIR $OPTIONS" + $svc_exec $validate_options +} + +restart() { + validate_config + retval = $? + if [ $retval -eq 0 ]; then + stop + retval=$? + + if [ $retval -eq 0 ] || [ $retval -eq 3 ]; then + start + else + return $retval + fi + else + return $retval + fi +} + +start() { + set_sensu_paths + ensure_dir $PID_DIR $LOG_DIR $USER + + if [ "x$forking" = "fork" ]; then + $svc_exec $options + else + exec $svc_exec $options + fi +} + +stop() { + pid=$(pid_pgrep) + + if [ ! -n "$pid" ]; then + # try the pid file + if [ -f "$pidfile" ] ; then + read pid < "$pidfile" + fi + fi + + if [ -n "$pid" ]; then + kill $pid + + retval=$? + + if [ $retval -eq 0 ]; then + wait_for_stop + + retval=$? + + if [ $retval -eq 0 ]; then + echo_ok + else + log_failure_msg "Timed out waiting for $sensu_service to stop" + echo_fail + fi + else + echo_fail + fi + + return $retval + else + log_action_msg "$sensu_service is stopped" + return 3 + fi +} + +case "$action" in + start) + start + ;; + stop) + stop + ;; + restart) + restart + ;; + validate_config) + validate_config + ;; + *) + echo "Usage: $0 {client|server|api} {start|stop|restart}" + exit 2 +esac + +exit $? + From b917b44e33555bd01cb0bef8ea4e72ad131ef7cf Mon Sep 17 00:00:00 2001 From: Cameron Johnston Date: Wed, 24 Aug 2016 12:39:03 -0600 Subject: [PATCH 2/9] cleanup sensu-service stub to remove unnecessary functions, correct usage output --- sensu_configs/bin/sensu-service | 102 +++----------------------------- 1 file changed, 8 insertions(+), 94 deletions(-) diff --git a/sensu_configs/bin/sensu-service b/sensu_configs/bin/sensu-service index b3279f2..529d85d 100755 --- a/sensu_configs/bin/sensu-service +++ b/sensu_configs/bin/sensu-service @@ -9,11 +9,10 @@ CONFIG_DIR=/etc/sensu/conf.d EXTENSION_DIR=/etc/sensu/extensions PLUGINS_DIR=/etc/sensu/plugins HANDLERS_DIR=/etc/sensu/handlers +PID_DIR=/var/run/sensu LOG_DIR=/var/log/sensu LOG_LEVEL=info -PID_DIR=/var/run/sensu USER=sensu -SERVICE_MAX_WAIT=10 if [ -f /etc/default/sensu ]; then . /etc/default/sensu @@ -48,112 +47,27 @@ set_sensu_paths() { fi } -echo_ok() { - echo_success; echo -} -echo_fail() { - echo_failure; echo -} -log_success_msg() { - success $"$@" -} -log_failure_msg() { - failure $"$@" - echo $"$@" -} -log_action_msg() { - echo $@ -} - -pid_pgrep() { - pgrep -f -P 1 -u $USER " $svc_exec " -} - -validate_config() { +validate() { validate_options="--validate_config -b -c $CONFIG_FILE -d $CONFIG_DIR -e $EXTENSION_DIR $OPTIONS" $svc_exec $validate_options } -restart() { - validate_config - retval = $? - if [ $retval -eq 0 ]; then - stop - retval=$? - - if [ $retval -eq 0 ] || [ $retval -eq 3 ]; then - start - else - return $retval - fi - else - return $retval - fi -} - start() { set_sensu_paths - ensure_dir $PID_DIR $LOG_DIR $USER - - if [ "x$forking" = "fork" ]; then - $svc_exec $options - else - exec $svc_exec $options - fi -} - -stop() { - pid=$(pid_pgrep) - - if [ ! -n "$pid" ]; then - # try the pid file - if [ -f "$pidfile" ] ; then - read pid < "$pidfile" - fi - fi - - if [ -n "$pid" ]; then - kill $pid - - retval=$? - - if [ $retval -eq 0 ]; then - wait_for_stop - - retval=$? - - if [ $retval -eq 0 ]; then - echo_ok - else - log_failure_msg "Timed out waiting for $sensu_service to stop" - echo_fail - fi - else - echo_fail - fi - - return $retval - else - log_action_msg "$sensu_service is stopped" - return 3 - fi + ensure_dir $PID_DIR $USER + ensure_dir $LOG_DIR $USER + exec $svc_exec $options } case "$action" in start) start ;; - stop) - stop - ;; - restart) - restart - ;; - validate_config) - validate_config + validate) + validate ;; *) - echo "Usage: $0 {client|server|api} {start|stop|restart}" + echo "Usage: $0 {start|validate} {client|server|api} [fork]" exit 2 esac From c64c3d817be7a3600857b87d8b305d5a3bde6b48 Mon Sep 17 00:00:00 2001 From: Cameron Johnston Date: Wed, 24 Aug 2016 12:39:58 -0600 Subject: [PATCH 3/9] modify sensu-service init script to use sensu-service bin stub --- sensu_configs/init.d/sensu-service | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/sensu_configs/init.d/sensu-service b/sensu_configs/init.d/sensu-service index 6c78390..e7d47c2 100755 --- a/sensu_configs/init.d/sensu-service +++ b/sensu_configs/init.d/sensu-service @@ -12,6 +12,7 @@ # Description: Sensu monitoring framework service script ### END INIT INFO +short_service=$1 sensu_service=sensu-$1 EMBEDDED_RUBY=true @@ -147,20 +148,12 @@ fi cd /opt/sensu -exec=/opt/sensu/bin/$sensu_service +exec="/opt/sensu/bin/sensu-service" pidfile=$PID_DIR/$sensu_service.pid logfile=$LOG_DIR/$sensu_service.log -options="-b -c $CONFIG_FILE -d $CONFIG_DIR -e $EXTENSION_DIR -p $pidfile -l $logfile -L $LOG_LEVEL $OPTIONS" - -ensure_dir() { - if [ ! -d $1 ]; then - mkdir -p $1 - chown -R $2 $1 - chmod 755 $1 - fi -} +options="start $short_service fork" set_sensu_paths() { if [ "x$EMBEDDED_RUBY" = "xtrue" ]; then @@ -197,12 +190,6 @@ wait_for_stop() { return $stopped } -deregister_client() { - log_action_msg "Deregistering sensu-client" - echo "{ \"name\": \"api_call\", \"output\": \"delete\", \"process\": \"init\", \"user\": \"root\", \"status\": 1, \"handler\": \"${CLIENT_DEREGISTER_HANDLER}\"}" > \ - /dev/tcp/localhost/3030 -} - start() { log_daemon_msg "Starting $sensu_service" @@ -216,10 +203,6 @@ start() { exit 0 fi - set_sensu_paths - ensure_dir $PID_DIR $USER - ensure_dir $LOG_DIR $USER - start_daemon $USER $pidfile $exec "$options" retval=$? @@ -241,9 +224,6 @@ start() { } stop() { - if [ "x$CLIENT_DEREGISTER_ON_STOP" = "xtrue" ]; then - deregister_client - fi log_daemon_msg "Stopping $sensu_service" # try pgrep @@ -321,8 +301,7 @@ status() { validate_config() { validate_pidfile=$PID_DIR/$sensu_service-validate.pid - validate_options="--validate_config -b -c $CONFIG_FILE -d $CONFIG_DIR -e $EXTENSION_DIR -p $validate_pidfile $OPTIONS" - start_daemon $USER $validate_pidfile $exec "$validate_options" + start_daemon $USER $validate_pidfile $exec "validate $short_service fork" } restart() { From 7a1527879e14b57d550001e9a718c902f2a0868d Mon Sep 17 00:00:00 2001 From: Cameron Johnston Date: Wed, 24 Aug 2016 12:41:27 -0600 Subject: [PATCH 4/9] rename sensu-service init script to sensu-service-wrapper --- sensu_configs/init.d/sensu-api | 2 +- sensu_configs/init.d/sensu-client | 2 +- sensu_configs/init.d/sensu-server | 2 +- sensu_configs/init.d/{sensu-service => sensu-service-wrapper} | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename sensu_configs/init.d/{sensu-service => sensu-service-wrapper} (100%) diff --git a/sensu_configs/init.d/sensu-api b/sensu_configs/init.d/sensu-api index ac91cf5..51885eb 100755 --- a/sensu_configs/init.d/sensu-api +++ b/sensu_configs/init.d/sensu-api @@ -12,6 +12,6 @@ # Description: Sensu monitoring framework api ### END INIT INFO -/etc/init.d/sensu-service api $1 +/etc/init.d/sensu-service-wrapper api $1 exit $? diff --git a/sensu_configs/init.d/sensu-client b/sensu_configs/init.d/sensu-client index a24fd60..e5ee0a3 100755 --- a/sensu_configs/init.d/sensu-client +++ b/sensu_configs/init.d/sensu-client @@ -12,6 +12,6 @@ # Description: Sensu monitoring framework client ### END INIT INFO -/etc/init.d/sensu-service client $1 +/etc/init.d/sensu-service-wrapper client $1 exit $? diff --git a/sensu_configs/init.d/sensu-server b/sensu_configs/init.d/sensu-server index d785b2b..42e5175 100755 --- a/sensu_configs/init.d/sensu-server +++ b/sensu_configs/init.d/sensu-server @@ -12,6 +12,6 @@ # Description: Sensu monitoring framework server ### END INIT INFO -/etc/init.d/sensu-service server $1 +/etc/init.d/sensu-service-wrapper server $1 exit $? diff --git a/sensu_configs/init.d/sensu-service b/sensu_configs/init.d/sensu-service-wrapper similarity index 100% rename from sensu_configs/init.d/sensu-service rename to sensu_configs/init.d/sensu-service-wrapper From 4b8a74366acca528bdfc4af376e34c29b4547a65 Mon Sep 17 00:00:00 2001 From: Cameron Johnston Date: Wed, 24 Aug 2016 12:44:00 -0600 Subject: [PATCH 5/9] update systemd service units to use new sensu-service bin stub --- sensu_configs/systemd/sensu-api.service | 2 +- sensu_configs/systemd/sensu-client.service | 4 ++-- sensu_configs/systemd/sensu-server.service | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sensu_configs/systemd/sensu-api.service b/sensu_configs/systemd/sensu-api.service index 9b778f9..68d27f8 100644 --- a/sensu_configs/systemd/sensu-api.service +++ b/sensu_configs/systemd/sensu-api.service @@ -4,7 +4,7 @@ Description=sensu api [Service] User=sensu Group=sensu -ExecStart=/opt/sensu/bin/sensu-api -c /etc/sensu/config.json -d /etc/sensu/conf.d -e /etc/sensu/extensions -l /var/log/sensu/sensu-api.log +ExecStart=/opt/sensu/bin/sensu-service start api KillMode=process Restart=on-failure RestartSec=1min diff --git a/sensu_configs/systemd/sensu-client.service b/sensu_configs/systemd/sensu-client.service index 8b1142e..d32f1a5 100644 --- a/sensu_configs/systemd/sensu-client.service +++ b/sensu_configs/systemd/sensu-client.service @@ -4,10 +4,10 @@ Description=sensu client [Service] User=sensu Group=sensu -ExecStart=/opt/sensu/bin/sensu-client -c /etc/sensu/config.json -d /etc/sensu/conf.d -e /etc/sensu/extensions -l /var/log/sensu/sensu-client.log +ExecStart=/opt/sensu/bin/sensu-service start client KillMode=process Restart=on-failure RestartSec=1min [Install] -WantedBy=multi-user.target +WantedBy=multi-user.target \ No newline at end of file diff --git a/sensu_configs/systemd/sensu-server.service b/sensu_configs/systemd/sensu-server.service index b61482c..32815c5 100644 --- a/sensu_configs/systemd/sensu-server.service +++ b/sensu_configs/systemd/sensu-server.service @@ -4,7 +4,7 @@ Description=sensu server [Service] User=sensu Group=sensu -ExecStart=/opt/sensu/bin/sensu-server -c /etc/sensu/config.json -d /etc/sensu/conf.d -e /etc/sensu/extensions -l /var/log/sensu/sensu-server.log +ExecStart=/opt/sensu/bin/sensu-service start server KillMode=process Restart=on-failure RestartSec=1min From 1cebf924071571a89c9e832ad81986c8b762284f Mon Sep 17 00:00:00 2001 From: Cameron Johnston Date: Wed, 24 Aug 2016 12:46:07 -0600 Subject: [PATCH 6/9] update rakefile for renamed sensu-service-wrapper init script --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 11576a5..6a567f1 100644 --- a/Rakefile +++ b/Rakefile @@ -71,7 +71,7 @@ Bunchr::Packages.new do |t| # all linux platforms are currently using init.d # this may change in the future. - t.files << '/etc/init.d/sensu-service' + t.files << '/etc/init.d/sensu-service-wrapper' t.files << '/etc/init.d/sensu-api' t.files << '/etc/init.d/sensu-client' t.files << '/etc/init.d/sensu-server' From 83445c31e00f6cf87cbaa8d8fcd92eb71d574dea Mon Sep 17 00:00:00 2001 From: Cameron Johnston Date: Wed, 24 Aug 2016 14:51:22 -0600 Subject: [PATCH 7/9] update upstart configurations for sensu-service bin stub --- sensu_configs/upstart/sensu-api.conf | 23 ++------------------ sensu_configs/upstart/sensu-client.conf | 28 +++++-------------------- sensu_configs/upstart/sensu-server.conf | 23 ++------------------ 3 files changed, 9 insertions(+), 65 deletions(-) diff --git a/sensu_configs/upstart/sensu-api.conf b/sensu_configs/upstart/sensu-api.conf index a9efe20..3bb9ca3 100644 --- a/sensu_configs/upstart/sensu-api.conf +++ b/sensu_configs/upstart/sensu-api.conf @@ -7,7 +7,7 @@ stop on [!12345] respawn -env PROG=sensu-api +env PROG=sensu-service chdir /opt/sensu/bin @@ -16,30 +16,11 @@ pre-start script end script script - EMBEDDED_RUBY=true - CONFIG_FILE=/etc/sensu/config.json - CONFIG_DIR=/etc/sensu/conf.d - EXTENSION_DIR=/etc/sensu/extensions - PLUGINS_DIR=/etc/sensu/plugins - HANDLERS_DIR=/etc/sensu/handlers - LOG_DIR=/var/log/sensu - LOG_LEVEL=info USER=sensu if [ -f /etc/default/sensu ]; then . /etc/default/sensu fi - logfile=$LOG_DIR/$PROG.log - - options="-c $CONFIG_FILE -d $CONFIG_DIR -e $EXTENSION_DIR -l $logfile -L $LOG_LEVEL $OPTIONS" - - if [ "x$EMBEDDED_RUBY" = "xtrue" ]; then - export PATH=/opt/sensu/embedded/bin:$PATH:$PLUGINS_DIR:$HANDLERS_DIR - export GEM_PATH=/opt/sensu/embedded/lib/ruby/gems/2.3.0:$GEM_PATH - else - export PATH=$PATH:$PLUGINS_DIR:$HANDLERS_DIR - fi - - exec setuidgid $USER ./$PROG $options + exec setuidgid $USER ./$PROG start api end script diff --git a/sensu_configs/upstart/sensu-client.conf b/sensu_configs/upstart/sensu-client.conf index 039f10b..944f31e 100644 --- a/sensu_configs/upstart/sensu-client.conf +++ b/sensu_configs/upstart/sensu-client.conf @@ -1,5 +1,7 @@ # Upstart: /etc/init/sensu-client.conf +OPTIONS="start client" + description "sensu client" start on (local-filesystems and net-device-up) @@ -7,7 +9,7 @@ stop on [!12345] respawn -env PROG=sensu-client +env PROG=sensu-service chdir /opt/sensu/bin @@ -16,30 +18,10 @@ pre-start script end script script - EMBEDDED_RUBY=true - CONFIG_FILE=/etc/sensu/config.json - CONFIG_DIR=/etc/sensu/conf.d - EXTENSION_DIR=/etc/sensu/extensions - PLUGINS_DIR=/etc/sensu/plugins - HANDLERS_DIR=/etc/sensu/handlers - LOG_DIR=/var/log/sensu - LOG_LEVEL=info USER=sensu if [ -f /etc/default/sensu ]; then - . /etc/default/sensu - fi - - logfile=$LOG_DIR/$PROG.log - - options="-c $CONFIG_FILE -d $CONFIG_DIR -e $EXTENSION_DIR -l $logfile -L $LOG_LEVEL $OPTIONS" - - if [ "x$EMBEDDED_RUBY" = "xtrue" ]; then - export PATH=/opt/sensu/embedded/bin:$PATH:$PLUGINS_DIR:$HANDLERS_DIR - export GEM_PATH=/opt/sensu/embedded/lib/ruby/gems/2.3.0:$GEM_PATH - else - export PATH=$PATH:$PLUGINS_DIR:$HANDLERS_DIR + . /etc/default/sensu fi - - exec setuidgid $USER ./$PROG $options + exec setuidgid $USER $PROG start client end script diff --git a/sensu_configs/upstart/sensu-server.conf b/sensu_configs/upstart/sensu-server.conf index 66a1bfb..f2cf01b 100644 --- a/sensu_configs/upstart/sensu-server.conf +++ b/sensu_configs/upstart/sensu-server.conf @@ -7,7 +7,7 @@ stop on [!12345] respawn -env PROG=sensu-server +env PROG=sensu-service chdir /opt/sensu/bin @@ -16,30 +16,11 @@ pre-start script end script script - EMBEDDED_RUBY=true - CONFIG_FILE=/etc/sensu/config.json - CONFIG_DIR=/etc/sensu/conf.d - EXTENSION_DIR=/etc/sensu/extensions - PLUGINS_DIR=/etc/sensu/plugins - HANDLERS_DIR=/etc/sensu/handlers - LOG_DIR=/var/log/sensu - LOG_LEVEL=info USER=sensu if [ -f /etc/default/sensu ]; then . /etc/default/sensu fi - logfile=$LOG_DIR/$PROG.log - - options="-c $CONFIG_FILE -d $CONFIG_DIR -e $EXTENSION_DIR -l $logfile -L $LOG_LEVEL $OPTIONS" - - if [ "x$EMBEDDED_RUBY" = "xtrue" ]; then - export PATH=/opt/sensu/embedded/bin:$PATH:$PLUGINS_DIR:$HANDLERS_DIR - export GEM_PATH=/opt/sensu/embedded/lib/ruby/gems/2.3.0:$GEM_PATH - else - export PATH=$PATH:$PLUGINS_DIR:$HANDLERS_DIR - fi - - exec setuidgid $USER ./$PROG $options + exec setuidgid $USER ./$PROG start server end script From 43e1a6d4e23ec044fffd093b55aecc1fcf12ae47 Mon Sep 17 00:00:00 2001 From: Cameron Johnston Date: Wed, 24 Aug 2016 14:54:05 -0600 Subject: [PATCH 8/9] rename sensu-service-wrapper to sensu-service-init --- Rakefile | 2 +- sensu_configs/init.d/sensu-api | 2 +- sensu_configs/init.d/sensu-client | 2 +- sensu_configs/init.d/sensu-server | 2 +- .../init.d/{sensu-service-wrapper => sensu-service-init} | 0 5 files changed, 4 insertions(+), 4 deletions(-) rename sensu_configs/init.d/{sensu-service-wrapper => sensu-service-init} (100%) diff --git a/Rakefile b/Rakefile index 6a567f1..5908b4c 100644 --- a/Rakefile +++ b/Rakefile @@ -71,7 +71,7 @@ Bunchr::Packages.new do |t| # all linux platforms are currently using init.d # this may change in the future. - t.files << '/etc/init.d/sensu-service-wrapper' + t.files << '/etc/init.d/sensu-service-init' t.files << '/etc/init.d/sensu-api' t.files << '/etc/init.d/sensu-client' t.files << '/etc/init.d/sensu-server' diff --git a/sensu_configs/init.d/sensu-api b/sensu_configs/init.d/sensu-api index 51885eb..2642c95 100755 --- a/sensu_configs/init.d/sensu-api +++ b/sensu_configs/init.d/sensu-api @@ -12,6 +12,6 @@ # Description: Sensu monitoring framework api ### END INIT INFO -/etc/init.d/sensu-service-wrapper api $1 +/etc/init.d/sensu-service-init api $1 exit $? diff --git a/sensu_configs/init.d/sensu-client b/sensu_configs/init.d/sensu-client index e5ee0a3..da69294 100755 --- a/sensu_configs/init.d/sensu-client +++ b/sensu_configs/init.d/sensu-client @@ -12,6 +12,6 @@ # Description: Sensu monitoring framework client ### END INIT INFO -/etc/init.d/sensu-service-wrapper client $1 +/etc/init.d/sensu-service-init client $1 exit $? diff --git a/sensu_configs/init.d/sensu-server b/sensu_configs/init.d/sensu-server index 42e5175..f90409f 100755 --- a/sensu_configs/init.d/sensu-server +++ b/sensu_configs/init.d/sensu-server @@ -12,6 +12,6 @@ # Description: Sensu monitoring framework server ### END INIT INFO -/etc/init.d/sensu-service-wrapper server $1 +/etc/init.d/sensu-service-init server $1 exit $? diff --git a/sensu_configs/init.d/sensu-service-wrapper b/sensu_configs/init.d/sensu-service-init similarity index 100% rename from sensu_configs/init.d/sensu-service-wrapper rename to sensu_configs/init.d/sensu-service-init From 5f082dcd963e5d0ccee4da093b565ba5fc4e096a Mon Sep 17 00:00:00 2001 From: Cameron Johnston Date: Wed, 24 Aug 2016 14:57:38 -0600 Subject: [PATCH 9/9] rename service variables in sensu-service-init script --- sensu_configs/init.d/sensu-service-init | 48 ++++++++++++------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/sensu_configs/init.d/sensu-service-init b/sensu_configs/init.d/sensu-service-init index e7d47c2..0a7e46b 100755 --- a/sensu_configs/init.d/sensu-service-init +++ b/sensu_configs/init.d/sensu-service-init @@ -12,8 +12,8 @@ # Description: Sensu monitoring framework service script ### END INIT INFO -short_service=$1 -sensu_service=sensu-$1 +sensu_service=$1 +service_name=sensu-$1 EMBEDDED_RUBY=true CONFIG_FILE=/etc/sensu/config.json @@ -59,7 +59,7 @@ fi ## Each platform must implement at least the following functions: ## ## start_daemon $user $pidfile $executable "arguments" -## killproc -p $pid $sensu_service +## killproc -p $pid $service_name ## log_daemon_msg $@ ## log_action_msg $@ ## log_success_msg $@ @@ -70,10 +70,10 @@ fi if [ "$system" = "redhat" ]; then ## source platform specific external scripts . /etc/init.d/functions - [ -r /etc/sysconfig/$sensu_service ] && . /etc/sysconfig/$sensu_service + [ -r /etc/sysconfig/$service_name ] && . /etc/sysconfig/$service_name ## set or override platform specific variables - lockfile=${LOCKFILE-/var/lock/subsys/$sensu_service} + lockfile=${LOCKFILE-/var/lock/subsys/$service_name} ## set or override platform specific functions start_daemon() { @@ -103,10 +103,10 @@ fi if [ "$system" = "debian" ]; then ## source platform specific external scripts . /lib/lsb/init-functions - [ -r /etc/default/$sensu_service ] && . /etc/default/$sensu_service + [ -r /etc/default/$service_name ] && . /etc/default/$service_name ## set or override platform specific variables - lockfile=${LOCKFILE-/var/lock/$sensu_service} + lockfile=${LOCKFILE-/var/lock/$service_name} ## set or override platform specific functions start_daemon() { @@ -123,10 +123,10 @@ fi if [ "$system" = "suse" ]; then ## source platform specific external scripts . /lib/lsb/init-functions - [ -r /etc/default/$sensu_service ] && . /etc/default/$sensu_service + [ -r /etc/default/$service_name ] && . /etc/default/$service_name ## set or override platform specific variables - lockfile=${LOCKFILE-/var/lock/subsys/$sensu_service} + lockfile=${LOCKFILE-/var/lock/subsys/$service_name} ## set or override platform specific functions start_daemon() { @@ -150,10 +150,10 @@ cd /opt/sensu exec="/opt/sensu/bin/sensu-service" -pidfile=$PID_DIR/$sensu_service.pid -logfile=$LOG_DIR/$sensu_service.log +pidfile=$PID_DIR/$service_name.pid +logfile=$LOG_DIR/$service_name.log -options="start $short_service fork" +options="start $service_name fork" set_sensu_paths() { if [ "x$EMBEDDED_RUBY" = "xtrue" ]; then @@ -191,14 +191,14 @@ wait_for_stop() { } start() { - log_daemon_msg "Starting $sensu_service" + log_daemon_msg "Starting $service_name" [ -x $exec ] || exit 5 status &> /dev/null if [ $? -eq 0 ]; then - log_action_msg "$sensu_service is already running." + log_action_msg "$service_name is already running." echo_ok exit 0 fi @@ -224,7 +224,7 @@ start() { } stop() { - log_daemon_msg "Stopping $sensu_service" + log_daemon_msg "Stopping $service_name" # try pgrep pid=$(pid_pgrep) @@ -249,7 +249,7 @@ stop() { if [ $retval -eq 0 ]; then echo_ok else - log_failure_msg "Timed out waiting for $sensu_service to stop" + log_failure_msg "Timed out waiting for $service_name to stop" echo_fail fi else @@ -258,7 +258,7 @@ stop() { return $retval else - log_action_msg "$sensu_service is stopped" + log_action_msg "$service_name is stopped" return 3 fi } @@ -270,7 +270,7 @@ status() { pid=$(pid_pgrep) if [ -n "$pid" ]; then - log_action_msg "$sensu_service (pid $pid) is running" + log_action_msg "$service_name (pid $pid) is running" return 0 fi @@ -281,27 +281,27 @@ status() { kill -0 $pid if [ $? -eq 0 ]; then - log_action_msg "$sensu_service (pid $pid) is running" + log_action_msg "$service_name (pid $pid) is running" return 0 else - log_action_msg "$sensu_service dead but pid file exists" + log_action_msg "$service_name dead but pid file exists" return 1 fi fi # check for the lock file if [ -f "$lockfile" ]; then - log_action_msg "$sensu_service dead but subsys locked" + log_action_msg "$service_name dead but subsys locked" return 2 fi - log_action_msg "$sensu_service is stopped" + log_action_msg "$service_name is stopped" return 3 } validate_config() { - validate_pidfile=$PID_DIR/$sensu_service-validate.pid - start_daemon $USER $validate_pidfile $exec "validate $short_service fork" + validate_pidfile=$PID_DIR/$service_name-validate.pid + start_daemon $USER $validate_pidfile $exec "validate $service_name fork" } restart() {