3 # functions This file contains functions to be used by most or all
4 # shell scripts in the /etc/init.d directory.
6 # Version: @(#) /etc/init.d/functions 1.01 26-Oct-1993
8 # Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
9 # Hacked by: Greg Galloway and Marc Ewing
10 # Modified for PLD by Marek Obuchowicz <elephant@shadow.eu.org>
13 # First set up a default search path.
14 export PATH="/sbin:/usr/sbin:/bin:/usr/bin"
16 # Some functions to handle PLD-style messages
18 text="$*".............................................
19 echo -ne `echo $text | cut -c1-45`
23 echo -ne '\e[0;36m[\e[0;35m BUSY \e[0;36m]\e[0;37m'
27 echo -e '\e[0;36m[\e[0;32m DONE \e[0;36m]\e[0;37m'
31 echo -e '\e[0;36m[\e[0;31m FAIL \e[0;36m]\e[0;37m'
35 echo -e '\e[0;36m[\e[0;31m DIED \e[0;36m]\e[0;37m'
39 echo -ne '\b\b\b\b\b\b\b\b'
42 # A function to start a program.
44 TMPFILE=`mktemp /tmp/init-XXXXXX`
49 '') echo '$0: Usage: daemon [+/-nicelevel] {program}'
55 # make sure it doesn't core dump anywhere; while this could mask
56 # problems with the daemon, it also closes some security problems
61 if nice -n $nicelevel "$@" &> $TMPFILE; then
72 # A function to stop a program.
76 echo "Usage: killproc {program} [signal]"
82 TMPFILE=`mktemp /tmp/init-XXXXXX`
85 # check for second arg to be kill level
86 if [ "$2" != "" ] ; then
100 if [ "$pid" != "" ] ; then
101 if [ "$notset" = 1 ] ; then
102 # TERM first, then KILL if not dead
103 kill -TERM $pid &> $TMPFILE
105 dead=`ps aux | awk '{print $2}' | grep $pid`
106 if [ "$dead" != "" ]; then
108 kill -KILL $pid &> $TMPFILE
110 # use specified level only
112 kill $killlevel $pid &> $TMPFILE
115 rm -f /var/run/$base.pid
121 # Remove pid file if any.
122 rm -f /var/run/$base.pid
124 if [ -z "`cat $TMPFILE`" ]; then
134 # A function to find the pid of a program.
138 echo "Usage: pidofproc {program}"
142 # First try "/var/run/*.pid" files
143 if [ -f /var/run/$1.pid ] ; then
144 pid=`head -1 /var/run/$1.pid`
145 if [ "$pid" != "" ] ; then
153 if [ "$pid" != "" ] ; then
158 # Finally try to extract it from ps
159 ps auxw | awk 'BEGIN { prog=ARGV[1]; ARGC=1 }
160 { if ((prog == $11) || (("(" prog ")") == $11) ||
161 ((prog ":") == $11)) { print $2 } }' $1
166 echo "Usage: status {program}"
172 if [ "$pid" != "" ] ; then
173 echo "$1 (pid $pid) is running..."
176 pid=`ps auxww | grep $1 | egrep -v grep\|$0 | awk '{print $2}'`
177 if [ "$pid" != "" ] ; then
178 echo "$1 (pid $pid) is running..."
183 # Next try "/var/run/*.pid" files
184 if [ -f /var/run/$1.pid ] ; then
185 pid=`head -1 /var/run/$1.pid`
186 if [ "$pid" != "" ] ; then
187 echo "$1 dead but pid file exists"
191 # See if /var/lock/subsys/$1 exists
192 if [ -f /var/lock/subsys/$1 ]; then
193 echo "$1 dead but subsys locked"