From 77215182f7f5df77b298124fb9a207c73aace935 Mon Sep 17 00:00:00 2001 From: "Haneysmith, Nathan" Date: Thu, 4 Jun 2015 11:01:04 -0700 Subject: [PATCH] fixing up init script exit codes --- packaging/deb/init.d/grafana-server | 12 +++++++----- packaging/rpm/init.d/grafana-server | 21 ++++++++++++++------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/packaging/deb/init.d/grafana-server b/packaging/deb/init.d/grafana-server index 6daebdb4331..6d021092de3 100755 --- a/packaging/deb/init.d/grafana-server +++ b/packaging/deb/init.d/grafana-server @@ -38,7 +38,12 @@ DAEMON=/usr/sbin/$NAME if [ `id -u` -ne 0 ]; then echo "You need root privileges to run this script" - exit 1 + exit 4 +fi + +if [ ! -x $DAEMON ]; then + echo "Program not installed or not executable" + exit 5 fi . /lib/lsb/init-functions @@ -54,9 +59,6 @@ fi DAEMON_OPTS="--pidfile=${PID_FILE} --config=${CONF_FILE} cfg:default.paths.data=${DATA_DIR} cfg:default.paths.logs=${LOG_DIR}" -# Check DAEMON exists -test -x $DAEMON || exit 0 - case "$1" in start) @@ -137,7 +139,7 @@ case "$1" in ;; *) log_success_msg "Usage: $0 {start|stop|restart|force-reload|status}" - exit 1 + exit 3 ;; esac diff --git a/packaging/rpm/init.d/grafana-server b/packaging/rpm/init.d/grafana-server index 60f8d0ff46c..ee99c8d7382 100755 --- a/packaging/rpm/init.d/grafana-server +++ b/packaging/rpm/init.d/grafana-server @@ -35,6 +35,16 @@ MAX_OPEN_FILES=10000 PID_FILE=/var/run/$NAME.pid DAEMON=/usr/sbin/$NAME +if [ `id -u` -ne 0 ]; then + echo "You need root privileges to run this script" + exit 4 +fi + +if [ ! -x $DAEMON ]; then + echo "Program not installed or not executable" + exit 5 +fi + # # init.d / servicectl compatibility (openSUSE) # @@ -55,9 +65,6 @@ fi DAEMON_OPTS="--pidfile=${PID_FILE} --config=${CONF_FILE} cfg:default.paths.data=${DATA_DIR} cfg:default.paths.logs=${LOG_DIR}" -# Check DAEMON exists -test -x $DAEMON || exit 0 - function isRunning() { status -p $PID_FILE $NAME > /dev/null 2>&1 } @@ -69,7 +76,7 @@ case "$1" in isRunning if [ $? -eq 0 ]; then echo "Already running." - exit 2 + exit 0 fi # Prepare environment @@ -90,7 +97,7 @@ case "$1" in # check if pid file has been written two if ! [[ -s $PID_FILE ]]; then echo "FAILED" - exit 3 + exit 1 fi i=0 timeout=10 @@ -101,7 +108,7 @@ case "$1" in i=$(($i + 1)) if [ $i -gt $timeout ]; then echo "FAILED" - exit 4 + exit 1 fi done fi @@ -141,6 +148,6 @@ case "$1" in ;; *) echo -n "Usage: $0 {start|stop|restart|force-reload|status}" - exit 1 + exit 3 ;; esac