Package: influxdb
Version: 0.13.0+dfsg1-4
Severity: normal
Tags: patch

Hi!

The attached file is a fixed and improveed init script for influxdb.
It removes things for which there's better guaranteed alternatives in
Debian and fixes few behavior nits.

Thanks,
Guillem
commit b5063ad4ff15aca76670f8635d292264fb34c3b1
Author: Guillem Jover <gjo...@sipwise.com>
Date:   Fri Sep 30 17:36:31 2016 +0200

    Fix init script

diff --git a/debian/influxdb.init b/debian/influxdb.init
index e9db2d0..71e54f8 100644
--- a/debian/influxdb.init
+++ b/debian/influxdb.init
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 ### BEGIN INIT INFO
 # Provides:          influxdb
@@ -32,13 +32,13 @@ USER=influxdb
 GROUP=influxdb
 
 if [ -r /lib/lsb/init-functions ]; then
-    source /lib/lsb/init-functions
+    . /lib/lsb/init-functions
 fi
 
 DEFAULT=/etc/default/influxdb
 
 if [ -r $DEFAULT ]; then
-    source $DEFAULT
+    . $DEFAULT
 fi
 
 if [ -z "$STDOUT" ]; then
@@ -58,48 +58,6 @@ fi
 
 OPEN_FILE_LIMIT=65536
 
-function pidofproc() {
-    if [ $# -ne 3 ]; then
-        echo "Expected three arguments, e.g. $0 -p pidfile daemon-name"
-    fi
-
-    pid=$(pgrep -f $3)
-    local pidfile=$(cat $2)
-
-    if [ "x$pidfile" == "x" ]; then
-        return 1
-    fi
-
-    if [ "x$pid" != "x" -a "$pidfile" == "$pid" ]; then
-        return 0
-    fi
-
-    return 1
-}
-
-function killproc() {
-    if [ $# -ne 3 ]; then
-        echo "Expected three arguments, e.g. $0 -p pidfile signal"
-    fi
-
-    PID=`cat $2`
-
-    /bin/kill -s $3 $PID
-    while true; do
-        pidof `basename $daemon` >/dev/null
-        if [ $? -ne 0 ]; then
-            return 0
-        fi
-
-        sleep 1
-        n=$(expr $n + 1)
-        if [ $n -eq 30 ]; then
-            /bin/kill -s SIGKILL $PID
-            return 0
-        fi
-    done
-}
-
 # Process name ( For display )
 name=influxd
 desc=database
@@ -122,45 +80,10 @@ config=/etc/influxdb/influxdb.conf
 # If the daemon is not there, then exit.
 [ -x $daemon ] || exit 0
 
-function wait_for_startup() {
-    control=1
-    while [ $control -lt 5 ]
-    do
-        if [ ! -e $pidfile ]; then
-            sleep 1
-            control=$((control+1))
-        else
-            break
-        fi
-    done
-}
-
-function is_process_running() {
-    # Checked the PID file exists and check the actual status of process
-    if [ -e $pidfile ]; then
-        pidofproc -p $pidfile $daemon > /dev/null 2>&1 && status="0" || status="$?"
-        # If the status is SUCCESS then don't need to start again.
-        if [ "x$status" = "x0" ]; then
-            return 0
-        else
-            return 1
-        fi
-    else
-        return 1
-    fi
-}
-
 case $1 in
     start)
         log_daemon_msg "Starting $desc" "$name"
 
-        # Check if it's running first
-        is_process_running
-        if [ $? -eq 0 ]; then
-            log_end_msg 0
-            exit 0
-        fi
-
         # Bump the file limits, before launching the daemon. These will carry over to
         # launched processes.
         ulimit -n $OPEN_FILE_LIMIT
@@ -170,41 +93,22 @@ case $1 in
             exit 1
         fi
 
-        if which start-stop-daemon > /dev/null 2>&1; then
-            start-stop-daemon --chuid $GROUP:$USER --start --quiet --pidfile $pidfile --exec $daemon -- -pidfile $pidfile -config $config $INFLUXD_OPTS >>$STDOUT 2>>$STDERR &
-        else
-            su $USER -c "nohup $daemon -pidfile $pidfile -config $config $INFLUXD_OPTS >>$STDOUT 2>>$STDERR &"
-        fi
+        start-stop-daemon --start --quiet --oknodo --exec $daemon \
+          --chuid $GROUP:$USER --pidfile $pidfile --background \
+          -- -pidfile $pidfile -config $config $INFLUXD_OPTS \
+          >>$STDOUT 2>>$STDERR
 
-        wait_for_startup && is_process_running
-        if [ $? -ne 0 ]; then
-            log_progress_msg "$name process failed to start"
-            log_end_msg 1
-            exit 1
-        else
-            log_end_msg 0
-            exit 0
-        fi
+        log_end_msg $?
         ;;
 
     stop)
         log_daemon_msg "Stopping $desc" "$name"
 
         # Stop the daemon.
-        is_process_running
-        if [ $? -ne 0 ]; then
-            log_progress_msg "$name process is not running"
-            log_end_msg 0
-            exit 0 # Exit
-        else
-            if killproc -p $pidfile SIGTERM && /bin/rm -rf $pidfile; then
-                log_end_msg 0
-                exit 0
-            else
-                log_end_msg 1
-                exit 1
-            fi
-        fi
+        start-stop-daemon --stop --quiet --oknodo \
+          --exec $daemon --pidfile $pidfile
+
+        log_end_msg $?
         ;;
 
     restart|force-reload)
@@ -216,19 +120,7 @@ case $1 in
         ;;
 
     status)
-        log_daemon_msg "Checking status of $desc" "$name"
-
-        # Check the status of the process.
-        is_process_running
-        if [ $? -eq 0 ]; then
-            log_progress_msg "running"
-            log_end_msg 0
-            exit 0
-        else
-            log_progress_msg "apparently not running"
-            log_end_msg 1
-            exit 1
-        fi
+        status_of_proc $daemon $name
         ;;
 
     version)
@@ -237,7 +129,7 @@ case $1 in
 
     *)
         # For invalid arguments, print the usage message.
-        echo "Usage: $0 {start|stop|restart|status|version}"
+        echo "Usage: $0 {start|stop|force-reload|restart|status|version}"
         exit 2
         ;;
 esac
_______________________________________________
Pkg-go-maintainers mailing list
Pkg-go-maintainers@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-go-maintainers

Reply via email to