From 71a02ad0f5e05e828ea68c8d049ac29d875de334 Mon Sep 17 00:00:00 2001 Date: Fri, 30 Nov 2018 18:46:40 +0300 Subject: [PATCH] Completion of init-script: added check of exit code, changed output of result of commands --- scripts/connman.in | 64 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 18 deletions(-) diff --git a/scripts/connman.in b/scripts/connman.in index 9f44a2d..b7d8964 100644 --- a/scripts/connman.in +++ b/scripts/connman.in @@ -11,8 +11,9 @@ DAEMON=@sbindir@/connmand DESC="Connection Manager" NAME=connmand +PIDFILE=/var/run/connman/$NAME.pid -. /lib/lsb/init-functions +. /etc/rc.d/init.d/functions if [ -f @sysconfdir@/default/connman ] ; then . @sysconfdir@/default/connman @@ -24,11 +25,11 @@ if [ "CONNMAN_RUNSTATEDIR_RESOLVCONF" != "no" ] ; then fi do_start() { - start-stop-daemon --start --oknodo --exec $DAEMON -- $DAEMON_OPTS + start-stop-daemon -S -q -b --make-pidfile --pidfile $PIDFILE --exec $DAEMON -- -n } do_stop() { - start-stop-daemon --stop --oknodo --quiet --exec $DAEMON + start-stop-daemon -K -q --remove-pidfile --pidfile $PIDFILE } get_pid() { @@ -40,32 +41,59 @@ get_pid() { string:$1 2>/dev/null | awk '/uint32/ {print $2}' } +checkrc() { + if [ $? = 0 ]; then + success + else + failure + fi +} + +success() +{ + echo -e "[ OK ]\r" +} + +failure() +{ + echo -e "[FAILED]\r" +} + case "$1" in start) - log_daemon_msg "Starting $DESC" - do_start - log_end_msg $? + #log_daemon_msg "Starting $DESC" + echo "Starting $DESC: $NAME" + pid=$( pidofproc -p $PIDFILE $DAEMON ) + if [ -n "$pid" ] ; then + echo "Already running" + exit 0 + fi + do_start + checkrc ;; stop) - log_daemon_msg "Stopping $DESC" - do_stop - log_end_msg $? + #log_daemon_msg "Stopping $DESC" + echo "Stopping $DESC: $NAME" + do_stop + checkrc ;; restart|force-reload) - log_daemon_msg "Restarting $DESC" - do_stop - sleep 1 - do_start - log_end_msg $? - ;; + #log_daemon_msg "Restarting $DESC" + echo "Restarting $DESC: " + do_stop + sleep 1 + do_start + ;; status) pid=$(get_pid net.connman) if [ -n "$pid" ]; then - log_success_msg "$NAME is running" + #log_success_msg "$NAME is running" + echo "$NAME is running" return 0 else - log_failure_msg "$NAME is not running" - return 3 # LSB exit code for "program is not running" + #log_failure_msg "$NAME is not running" + echo "$NAME is not running" + exit 3 # LSB exit code for "program is not running" fi ;; *) -- 2.16.4