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.9 $ $Date: 1999/06/19 11:29:04 $
6 # Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
7 # Hacked by: Greg Galloway and Marc Ewing
9 # Marek Obuchowicz <elephant@shadow.eu.org>
10 # Arkadiusz Mi¶kiewicz <misiek@pld.org.pl>
12 # First set up a default search path.
13 export PATH="/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin"
15 [ -z "$COLUMNS" ] && COLUMNS=80
19 if [ "$COLOR_INIT" == "no" ]; then
24 elif [ ! -d /usr/share/terminfo ]; then
27 if [ "$2" == "1" ]; then echo -ne "\033[0;31m"
28 elif [ "$2" == "2" ]; then echo -ne "\033[0;32m"
29 elif [ "$2" == "5" ]; then echo -ne "\033[0;35m"
30 elif [ "$2" == "6" ]; then echo -ne "\033[0;36m"
31 elif [ "$2" == "7" ]; then echo -ne "\033[0;37m"
38 # Some functions to handle PLD-style messages
41 text="$*".............................................
42 echo -ne `echo $text | cut -c1-45`
47 echo -n "`tput setaf 6`[`tput setaf 5` BUSY `tput setaf 6`]`tput setaf 7`"
52 echo "`tput setaf 6`[`tput setaf 2` DONE `tput setaf 6`]`tput setaf 7`"
57 echo "`tput setaf 6`[`tput setaf 2` WORK `tput setaf 6`]`tput setaf 7`"
62 echo "`tput setaf 6`[`tput setaf 1` FAIL `tput setaf 6`]`tput setaf 7`"
67 echo "`tput setaf 6`[`tput setaf 1` DIED `tput setaf 6`]`tput setaf 7`"
72 echo -ne '\b\b\b\b\b\b\b\b'
75 # Usage run_cmd Message command_to_run
82 if _ERRORS="`initlog -c \"$*\"`"; then
85 deltext; fail; echo $_ERRORS
92 # A function to start a program (now it's usefull on read-only filesystem too)
97 [ -z "$DEFAULT_SERVICE_RUN_NICE_LEVEL" ] && DEFAULT_SERVICE_RUN_NICE_LEVEL=0
100 '') echo '$0: Usage: daemon [+/-nicelevel] {program}'
102 -*|+*) SERVICE_RUN_NICE_LEVEL=$1
106 # make sure it doesn't core dump anywhere; while this could mask
107 # problems with the daemon, it also closes some security problems
112 if _ERRORS="`nice -n ${SERVICE_RUN_NICE_LEVEL:-$DEFAULT_SERVICE_RUN_NICE_LEVEL} initlog -c "$*" 2>&1`"; then
123 # A function to stop a program.
128 echo "Usage: killproc {program} [signal]"
134 TMPFILE=`mktemp /tmp/init-XXXXXX`
137 # check for second arg to be kill level
138 if [ "$2" != "" ] ; then
149 pid=`pidofproc $base`
152 if [ "$pid" != "" ] ; then
153 if [ "$notset" = 1 ] ; then
154 # TERM first, then KILL if not dead
155 kill -TERM $pid >$TMPFILE 2>&1
157 dead=`ps -o pid= $pid`
158 if [ "$dead" != "" ]; then
160 kill -KILL $pid >$TMPFILE 2>&1
162 # use specified level only
164 kill $killlevel $pid >$TMPFILE 2>&1
167 rm -f /var/run/$base.pid
173 # Remove pid file if any.
174 rm -f /var/run/$base.pid
176 if [ -z "`cat $TMPFILE`" ]; then
186 # A function to find the pid of a program.
191 echo "Usage: pidofproc {program}"
195 # First try "/var/run/*.pid" files
196 if [ -f /var/run/$1.pid ] ; then
197 pid=`head -1 /var/run/$1.pid`
198 if [ "$pid" != "" ] ; then
206 if [ "$pid" != "" ] ; then
211 # Finally try to extract it from ps
212 pids=`ps -C $1 -o pid=`
214 # Return the first PID, which is not our
215 for pid in $pids ; do
216 if [ $pid != $$ ] ; then
229 echo "Usage: status {program}"
235 if [ "$pid" != "" ] ; then
236 echo "$1 (pid $pid) is running..."
239 pid=`echo \`ps -C $1 -o pid= \``
240 if [ "$pid" != "" ] ; then
241 echo "$1 (pid $pid) is running..."
246 # Next try "/var/run/*.pid" files
247 if [ -f /var/run/$1.pid ] ; then
248 pid=`head -1 /var/run/$1.pid`
249 if [ "$pid" != "" ] ; then
250 echo "$1 dead but pid file exists"
254 # See if /var/lock/subsys/$1 exists
255 if [ -f /var/lock/subsys/$1 ]; then
256 echo "$1 dead but subsys locked"