contrib/rc/linux/dtlogin: Make the init script work.
authorIsaac Dunham <ibid.ag@gmail.com>
Sat, 7 Mar 2015 17:43:58 +0000 (17:43 +0000)
committerJon Trulson <jon@radscan.com>
Sun, 8 Mar 2015 02:44:55 +0000 (19:44 -0700)
* insserv requires a shebang line
* the rc script can hang if a daemon is started in the foreground
* "pgrep dtlogin" apparently can match the init script, if it is started
  with "service dtlogin start" or similar.
* reduce code duplication

cde/contrib/rc/linux/dtlogin

index 3a04ab552a12851e2c3de0d9818ab8046e94f1f2..c5f17a68825a70cc4ab676fdf7143916325ada2d 100644 (file)
@@ -1,3 +1,4 @@
+#!/bin/sh
 ### BEGIN INIT INFO
 # Provides:            lsb-dtlogin
 # Required-Start:      $all
@@ -8,38 +9,36 @@
 # Description:         Dtlogin
 ### END INIT INFO
 
+export PATH="/usr/dt/bin:$PATH"
+OPTIONS="-quiet -daemon"
+
+start(){
+       if [ -z "$(pgrep /usr/dt/bin/dtlogin)" ];
+       then
+               echo " * Starting dtlogin..."
+               export LANG=C
+               /usr/dt/bin/dtlogin $OPTIONS
+       fi
+}
+
+stop(){
+       if [ -n "$(pgrep /usr/dt/bin/dtlogin)" ];
+       then
+               echo " * Stopping dtlogin..."
+               killall /usr/dt/bin/dtlogin
+       fi
+}
+
 case "$1" in
        'start')
-               if [ -z "$(pgrep dtlogin)" ];
-               then
-                       echo " * Starting dtlogin..."
-                       export LANG=C
-                       exec /usr/dt/bin/dtlogin
-               else
-                       echo "DTlogin already running..."
-                       exit 0
-               fi
+               start
        ;;
        'stop')
-               if [ -z "$(pgrep dtlogin)" ];
-               then
-                       exit 0
-               else
-                       echo " * Stopping dtlogin..."
-                       killall /usr/dt/bin/dtlogin
-               fi
+               stop
        ;;
        'restart')
-               if [ -z "$(pgrep dtlogin)" ];
-               then
-                       export LANG=C
-                       exec /usr/dt/bin/dtlogin
-               else
-                       echo " * Restarting dtlogin..."
-                       killall /usr/dt/bin/dtlogin
-                       export LANG=C
-                       exec /usr/dt/bin/dtlogin        
-               fi
+               stop
+               start
        ;;
        'status')
                if [ -z "$(pgrep dtlogin)" ];