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
19 text="$*".............................................
20 echo -ne `echo $text | cut -c1-45`
25 echo -n "`tput setaf 6`[`tput setaf 5` BUSY `tput setaf 6`]`tput setaf 7`"
30 echo "`tput setaf 6`[`tput setaf 2` DONE `tput setaf 6`]`tput setaf 7`"
35 echo "`tput setaf 6`[`tput setaf 2` WORK `tput setaf 6`]`tput setaf 7`"
40 echo "`tput setaf 6`[`tput setaf 1` FAIL `tput setaf 6`]`tput setaf 7`"
45 echo "`tput setaf 6`[`tput setaf 1` DIED `tput setaf 6`]`tput setaf 7`"
50 echo -ne '\b\b\b\b\b\b\b\b'
53 # A function to start a program.
55 TMPFILE=`mktemp /tmp/init-XXXXXX`
60 '') echo '$0: Usage: daemon [+/-nicelevel] {program}'
66 # make sure it doesn't core dump anywhere; while this could mask
67 # problems with the daemon, it also closes some security problems
72 if nice -n $nicelevel "$@" &> $TMPFILE; then
83 # A function to stop a program.
87 echo "Usage: killproc {program} [signal]"
93 TMPFILE=`mktemp /tmp/init-XXXXXX`
96 # check for second arg to be kill level
97 if [ "$2" != "" ] ; then
108 pid=`pidofproc $base`
111 if [ "$pid" != "" ] ; then
112 if [ "$notset" = 1 ] ; then
113 # TERM first, then KILL if not dead
114 kill -TERM $pid &> $TMPFILE
116 dead=`ps aux | awk '{print $2}' | grep $pid`
117 if [ "$dead" != "" ]; then
119 kill -KILL $pid &> $TMPFILE
121 # use specified level only
123 kill $killlevel $pid &> $TMPFILE
126 rm -f /var/run/$base.pid
132 # Remove pid file if any.
133 rm -f /var/run/$base.pid
135 if [ -z "`cat $TMPFILE`" ]; then
145 # A function to find the pid of a program.
149 echo "Usage: pidofproc {program}"
153 # First try "/var/run/*.pid" files
154 if [ -f /var/run/$1.pid ] ; then
155 pid=`head -1 /var/run/$1.pid`
156 if [ "$pid" != "" ] ; then
164 if [ "$pid" != "" ] ; then
169 # Finally try to extract it from ps
170 ps auxw | awk 'BEGIN { prog=ARGV[1]; ARGC=1 }
171 { if ((prog == $11) || (("(" prog ")") == $11) ||
172 ((prog ":") == $11)) { print $2 } }' $1
177 echo "Usage: status {program}"
183 if [ "$pid" != "" ] ; then
184 echo "$1 (pid $pid) is running..."
187 pid=`ps auxww | grep $1 | egrep -v grep\|$0 | awk '{print $2}'`
188 if [ "$pid" != "" ] ; then
189 echo "$1 (pid $pid) is running..."
194 # Next try "/var/run/*.pid" files
195 if [ -f /var/run/$1.pid ] ; then
196 pid=`head -1 /var/run/$1.pid`
197 if [ "$pid" != "" ] ; then
198 echo "$1 dead but pid file exists"
202 # See if /var/lock/subsys/$1 exists
203 if [ -f /var/lock/subsys/$1 ]; then
204 echo "$1 dead but subsys locked"