aboutsummaryrefslogtreecommitdiffstats
path: root/rc.d/init.d/functions
diff options
context:
space:
mode:
authorErik Troan <ewt@redhat.com>1997-09-16 14:12:05 +0000
committerErik Troan <ewt@redhat.com>1997-09-16 14:12:05 +0000
commitced9dffda28f1ec2b060f3e419cf3c6b964b03a1 (patch)
treeda3f56c24861ddc77e2910291c71adc12dca136b /rc.d/init.d/functions
downloadinitscripts-ced9dffda28f1ec2b060f3e419cf3c6b964b03a1.tar
initscripts-ced9dffda28f1ec2b060f3e419cf3c6b964b03a1.tar.gz
initscripts-ced9dffda28f1ec2b060f3e419cf3c6b964b03a1.tar.bz2
initscripts-ced9dffda28f1ec2b060f3e419cf3c6b964b03a1.tar.xz
initscripts-ced9dffda28f1ec2b060f3e419cf3c6b964b03a1.zip
Initial revision
Diffstat (limited to 'rc.d/init.d/functions')
-rwxr-xr-xrc.d/init.d/functions139
1 files changed, 139 insertions, 0 deletions
diff --git a/rc.d/init.d/functions b/rc.d/init.d/functions
new file mode 100755
index 00000000..e3b1494e
--- /dev/null
+++ b/rc.d/init.d/functions
@@ -0,0 +1,139 @@
+#! /bin/sh
+#
+# functions This file contains functions to be used by most or all
+# shell scripts in the /etc/init.d directory.
+#
+# Version: @(#) /etc/init.d/functions 1.01 26-Oct-1993
+#
+# Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
+# Hacked by: Greg Galloway and Marc Ewing
+#
+
+# First set up a default search path.
+export PATH="/sbin:/usr/sbin:/bin:/usr/bin"
+
+# A function to start a program.
+daemon() {
+ # Test syntax.
+ if [ $# = 0 ]; then
+ echo "Usage: daemon {program}"
+ return 1
+ fi
+
+ # Save basename.
+ base=`basename $1`
+
+ # See if it's already running.
+ [ "`pidofproc $base`" != "" ] && return
+
+ # echo basename of the program.
+ echo -n "$base "
+
+ # And start it up.
+ $*
+}
+
+# A function to stop a program.
+killproc() {
+ # Test syntax.
+ if [ $# = 0 ]; then
+ echo "Usage: killproc {program} [signal]"
+ return 1
+ fi
+
+ notset=0
+ # check for second arg to be kill level
+ if [ "$2" != "" ] ; then
+ killlevel=$2
+ else
+ notset=1
+ killlevel="-9"
+ fi
+
+ # Save basename.
+ base=`basename $1`
+
+ # Find pid.
+ pid=`pidofproc $base`
+
+ # Kill it.
+ if [ "$pid" != "" ] ; then
+ echo -n "$base "
+ if [ "$notset" = 1 ] ; then
+ # TERM first, then KILL if not dead
+ kill -TERM $pid
+ usleep 10000
+ dead=`ps aux | awk "{print $2}" | grep $pid`
+ if [ "$dead" != "" ]; then
+ sleep 4
+ kill -KILL $pid
+ fi
+ # use specified level only
+ else
+ kill $killlevel $pid
+ fi
+ fi
+
+ # Remove pid file if any.
+ rm -f /var/run/$base.pid
+}
+
+# A function to find the pid of a program.
+pidofproc() {
+ # Test syntax.
+ if [ $# = 0 ] ; then
+ echo "Usage: pidofproc {program}"
+ return 1
+ fi
+
+ # First try "pidof"
+ pid=`pidof $1`
+ if [ "$pid" != "" ] ; then
+ echo $pid
+ return 0
+ fi
+
+ # Next try "/var/run/*.pid" files
+ if [ -f /var/run/$1.pid ] ; then
+ pid=`head -1 /var/run/$1.pid`
+ if [ "$pid" != "" ] ; then
+ echo $pid
+ return 0
+ fi
+ fi
+
+ # Finally try to extract it from ps
+ ps auxw | awk 'BEGIN { prog=ARGV[1]; ARGC=1 }
+ { if ((prog == $11) || (("(" prog ")") == $11) ||
+ ((prog ":") == $11)) { print $2 } }' $1
+}
+status() {
+ # Test syntax.
+ if [ $# = 0 ] ; then
+ echo "Usage: status {program}"
+ return 1
+ fi
+
+ # First try "pidof"
+ pid=`pidof $1`
+ if [ "$pid" != "" ] ; then
+ echo "$1 is running..."
+ return 0
+ fi
+
+ # Next try "/var/run/*.pid" files
+ if [ -f /var/run/$1.pid ] ; then
+ pid=`head -1 /var/run/$1.pid`
+ if [ "$pid" != "" ] ; then
+ echo "$1 dead but pid file exists"
+ return 1
+ fi
+ fi
+ # See if /var/lock/subsys/$1 exists
+ if [ -f /var/lock/subsys/$1 ]; then
+ echo "$1 dead but subsys locked"
+ return 2
+ fi
+ echo "$1 is stopped"
+ return 3
+}