From ea879fc8116ad07191a85a41ce92bcca903a944e Mon Sep 17 00:00:00 2001 From: lon Date: Fri, 9 Feb 2001 18:58:50 +0000 Subject: [PATCH] Initial distribution dependent daemon management functions for nfs init scripts. --- etc/nodist/nfs-functions | 104 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100755 etc/nodist/nfs-functions 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 +} + -- 2.39.5