]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
Initial distribution dependent daemon management functions for nfs init
authorlon <lon>
Fri, 9 Feb 2001 18:58:50 +0000 (18:58 +0000)
committerlon <lon>
Fri, 9 Feb 2001 18:58:50 +0000 (18:58 +0000)
scripts.

etc/nodist/nfs-functions [new file with mode: 0755]

diff --git a/etc/nodist/nfs-functions b/etc/nodist/nfs-functions
new file mode 100755 (executable)
index 0000000..1f7b050
--- /dev/null
@@ -0,0 +1,104 @@
+#!/bin/bash
+#
+# An attempt at a simple, distribution-independent daemon management.
+#
+# Copyright (C) 2000-2001 Mission Critical Linux, Inc.
+#
+
+# daemon functions
+getpid()
+{
+    pid=''
+    if [ -f /var/run/${base}.pid ] 
+    then
+        pid=`head -1 /var/run/${base}.pid`
+    fi
+    if [ "$pid" = "" ]
+    then
+        pid=`pidof $1`
+    fi
+    if [ "$pid" = "" ]
+    then
+        pid=`ps ax | awk 'BEGIN { prog=ARGV[1]; ARGC=1 }
+                   { if ((prog == $5) || (("(" prog ")") == $5) ||
+                     (("[" prog "]") == $5) ||
+                   ((prog ":") == $5)) { print $1 ; exit 0 } }' $1`
+    fi
+
+    echo $pid
+}
+
+startdaemon()
+{
+    base=`basename $1`
+
+    # check if it is already running
+    pid=`getpid $base`
+    [ -n "$pid" ] && ps h $pid >/dev/null 2>&1 && echo " already running." && return
+
+    # don't dump core
+    ulimit -c 0
+
+    $* && echo " done." || echo " failed."
+}
+
+stopdaemon()
+{
+    base=`basename $1`
+    pid=`getpid $base`
+
+    if [ "$pid" != "" ]
+    then
+        if ps h $pid>/dev/null 2>&1
+        then
+            kill -TERM $pid
+            if ps h $pid>/dev/null 2>&1
+            then
+                sleep 1
+                if ps h $pid>/dev/null 2>&1
+                then
+                    sleep 3
+                    if ps h $pid>/dev/null 2>&1
+                    then
+                        kill -KILL $pid
+                       sleep 2
+                    fi
+                fi
+            fi
+        fi
+        ps h $pid >/dev/null 2>&1
+        RC=$?
+        [ $RC -eq 0 ] && echo " failed." || echo " done."
+        [ $RC -eq 0 ] || rm -f /var/run/$base.pid >/dev/null 2>&1
+    else
+        echo " not running."
+    fi
+}
+
+daemonstatus()
+{
+    base=`basename $1`
+    pid=`getpid $base`
+    
+    if [ "$pid" != "" ]
+    then
+        if ps h $pid >/dev/null 2>&1
+        then
+            echo "$base (pid $pid) is running."
+            return 0
+        else
+            if [ -f /var/run/${base}.pid ]
+            then
+                echo "$base dead but pid file exists."
+                return 1
+            else
+                echo "$base is stopped."
+                return 2
+            fi
+        fi
+    else
+        echo "$base is stopped."
+        return 3
+    fi
+}
+