1 # functions This file contains functions to be used by most or all
2 # shell scripts in the /etc/init.d directory.
4 # Version: @(#) /etc/init.d/functions $Revision: 1.5 $ $Date: 1999/06/14 20:44:32 $
6 # Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
7 # Hacked by: Greg Galloway and Marc Ewing
8 # Modified for PLD by Marek Obuchowicz <elephant@shadow.eu.org>
11 # First set up a default search path.
12 PATH="/sbin:/usr/sbin:/bin:/usr/bin"; export PATH
14 # Some functions to handle PLD-style messages
16 text="$*".............................................
17 echo -ne `echo $text | cut -c1-45`
21 echo -n "`tput setaf 6`[`tput setaf 5` BUSY `tput setaf 6`]`tput setaf 7`"
25 echo "`tput setaf 6`[`tput setaf 2` DONE `tput setaf 6`]`tput setaf 7`"
29 echo "`tput setaf 6`[`tput setaf 1` FAIL `tput setaf 6`]`tput setaf 7`"
33 echo "`tput setaf 6`[`tput setaf 1` DIED `tput setaf 6`]`tput setaf 7`"
37 echo -ne '\b\b\b\b\b\b\b\b'
40 # A function to start a program.
42 TMPFILE=`mktemp /tmp/init-XXXXXX`
47 '') echo '$0: Usage: daemon [+/-nicelevel] {program}'
53 # make sure it doesn't core dump anywhere; while this could mask
54 # problems with the daemon, it also closes some security problems
59 if nice -n $nicelevel "$@" >$TMPFILE 2>&1; then
70 # A function to stop a program.
74 echo "Usage: killproc {program} [signal]"
80 TMPFILE=`mktemp /tmp/init-XXXXXX`
83 # check for second arg to be kill level
84 if [ "$2" != "" ] ; then
98 if [ "$pid" != "" ] ; then
99 if [ "$notset" = 1 ] ; then
100 # TERM first, then KILL if not dead
101 kill -TERM $pid >$TMPFILE 2>&1
103 dead=`ps -o pid= $pid`
104 if [ "$dead" != "" ]; then
106 kill -KILL $pid >$TMPFILE 2>&1
108 # use specified level only
110 kill $killlevel $pid >$TMPFILE 2>&1
113 rm -f /var/run/$base.pid
119 # Remove pid file if any.
120 rm -f /var/run/$base.pid
122 if [ -z "`cat $TMPFILE`" ]; then
132 # A function to find the pid of a program.
136 echo "Usage: pidofproc {program}"
140 # First try "/var/run/*.pid" files
141 if [ -f /var/run/$1.pid ] ; then
142 pid=`head -1 /var/run/$1.pid`
143 if [ "$pid" != "" ] ; then
151 if [ "$pid" != "" ] ; then
156 # Finally try to extract it from ps
157 pids=`ps -C $1 -o pid=`
159 # Return the first PID, which is not our
160 for pid in $pids ; do
161 if [ $pid != $$ ] ; then
173 echo "Usage: status {program}"
179 if [ "$pid" != "" ] ; then
180 echo "$1 (pid $pid) is running..."
183 pid=`echo \`ps -C $1 -o pid= \``
184 if [ "$pid" != "" ] ; then
185 echo "$1 (pid $pid) is running..."
190 # Next try "/var/run/*.pid" files
191 if [ -f /var/run/$1.pid ] ; then
192 pid=`head -1 /var/run/$1.pid`
193 if [ "$pid" != "" ] ; then
194 echo "$1 dead but pid file exists"
198 # See if /var/lock/subsys/$1 exists
199 if [ -f /var/lock/subsys/$1 ]; then
200 echo "$1 dead but subsys locked"