From: lon Date: Fri, 9 Feb 2001 18:58:50 +0000 (+0000) Subject: Initial distribution dependent daemon management functions for nfs init X-Git-Tag: nfs-utils-0-3-1~8 X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=ea879fc8116ad07191a85a41ce92bcca903a944e;p=nfs-utils.git Initial distribution dependent daemon management functions for nfs init scripts. --- diff --git a/etc/nodist/nfs-functions b/etc/nodist/nfs-functions new file mode 100755 index 0000000..1f7b050 --- /dev/null +++ b/etc/nodist/nfs-functions @@ -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 +} +