3 # bacula This shell script takes care of starting and stopping
6 # This is pretty much watered down version of the RedHat script
7 # that works on Solaris as well as Linux, but it won't work everywhere.
9 # description: It comes by night and sucks the vital essence from your computers.
14 # All these are not *really* needed but it makes it
15 # easier to "steal" this code for the development
16 # environment where they are different.
23 BACDIRCFG=@sysconfdir@
38 # A function to stop a program.
43 echo "Usage: killproc {program} [signal]"
48 # check for third arg to be kill level
49 if [ "$3" != "" ] ; then
56 # Get base program name
60 pid=`pidofproc $base $2`
63 if [ "$pid" != "" ] ; then
64 if [ "$notset" = "1" ] ; then
65 if ps -p $pid>/dev/null 2>&1; then
66 # TERM first, then KILL if not dead
67 kill -TERM $pid 2>/dev/null
69 if ps -p $pid >/dev/null 2>&1 ; then
71 if ps -p $pid >/dev/null 2>&1 ; then
73 if ps -p $pid >/dev/null 2>&1 ; then
74 kill -KILL $pid 2>/dev/null
79 ps -p $pid >/dev/null 2>&1
81 [ $RC -eq 0 ] && failure "$base shutdown" || success "$base shutdown"
83 # use specified level only
85 if ps -p $pid >/dev/null 2>&1; then
86 kill $killlevel $pid 2>/dev/null
88 [ $RC -eq 0 ] && success "$base $killlevel" || failure "$base $killlevel"
92 failure "$base shutdown"
94 # Remove pid file if any.
95 if [ "$notset" = "1" ]; then
96 rm -f ${PIDDIR}/$base.$2.pid
101 # A function to find the pid of a program.
106 echo "Usage: pidofproc {program}"
110 # Get base program name
114 if [ -f ${PIDDIR}/$base.$2.pid ] ; then
115 pid=`head -1 ${PIDDIR}/$base.$2.pid`
116 if [ "$pid" != "" ] ; then
123 if [ -x /sbin/pidof ] ; then
126 if [ "$pid" != "" ] ; then
131 # Finally try to extract it from ps
132 ${PSCMD} | grep $1 | awk '{ print $1 }' | tr '\n' ' '
139 echo "Usage: status {program}"
143 # Get base program name
147 if [ -x /sbin/pidof ] ; then
150 if [ "$pid" != "" ] ; then
151 echo "$base (pid $pid) is running..."
154 pid=`${PSCMD} | awk 'BEGIN { prog=ARGV[1]; ARGC=1 }
155 { if ((prog == $2) || (("(" prog ")") == $2) ||
156 (("[" prog "]") == $2) ||
157 ((prog ":") == $2)) { print $1 ; exit 0 } }' $1`
158 if [ "$pid" != "" ] ; then
159 echo "$base (pid $pid) is running..."
164 # Next try the PID files
165 if [ -f ${PIDDIR}/$base.$2.pid ] ; then
166 pid=`head -1 ${PIDDIR}/$base.$2.pid`
167 if [ "$pid" != "" ] ; then
168 echo "$base not running, but pid file exists"
172 # See if the subsys lock exists
173 if [ -f ${SUBSYSDIR}/$base ] ; then
174 echo "$base not running, but subsys locked"
177 echo "$base is stopped"