8 echo "Usage: ${ME} {start|stop|restart} [daemon ...]"
22 STATEDIR
=/var
/run
/quagga
23 DAEMONS
="zebra ripd ripngd ospfd ospf6d bgpd"
25 WATCHQUAGGA_FLAGS
="-d -z -T 60 -R"
26 WATCHQUAGGA_CMD
="sh $0 watchrestart"
27 if [ ${COMMAND} != "watchrestart" ]
29 DAEMONS
="${DAEMONS} watchquagga"
31 DAEMONS_STARTSEQ
=${DAEMONS}
44 DAEMONS_STOPSEQ
=$
(reverse
${DAEMONS_STARTSEQ})
47 # ps ax | awk 'match($5, "(^|/)'"$1"'$") > 0 { printf " %s", $1 }'
64 [ "$1" = "$i" ] && return 0
75 is_in
$i "$2" || unknown
="$unknown $i"
84 is_in
$j "$1" && RESULT
="$RESULT $j"
95 autostart|start|stop|restart
)
98 if [ -n "$ARG_DAEMONS" ]
100 echo "${ME}: watchrestart mode is only for use by watchquagga"
109 # select daemons to start
113 test x
"${quagga:-NO}" = x
"NO" && exit 0
114 test x
"$quagga" = x
"DAEMON" && test -x /bin
/mksh
&& exec mksh
-T- $0 start
117 start|restart|watchrestart
)
119 for d
in ${DAEMONS_STARTSEQ}
121 [ -x "${BINDIR}/${d}" -a -f "${CONFDIR}/${d}.conf" ] \
122 && START_DAEMONS
="${START_DAEMONS}${d} "
124 WATCHQUAGGA_DAEMONS
=${START_DAEMONS}
125 if is_in watchquagga
"${DAEMONS_STARTSEQ}"
127 START_DAEMONS
="${START_DAEMONS} watchquagga"
129 if [ -n "${ARG_DAEMONS}" ]
131 if select_subset
"${ARG_DAEMONS}" "${DAEMONS}"
133 if select_subset
"${ARG_DAEMONS}" "${START_DAEMONS}"
135 START_DAEMONS
=${RESULT}
137 die
"these daemons are not startable:${RESULT}."
140 die
"unknown daemons:${RESULT}; choose from: ${DAEMONS}."
146 # select daemons to stop
149 stop|restart|watchrestart
)
150 STOP_DAEMONS
=${DAEMONS_STOPSEQ}
151 if [ -n "${ARG_DAEMONS}" ]
153 if select_subset
"${ARG_DAEMONS}" "${STOP_DAEMONS}"
155 STOP_DAEMONS
=${RESULT}
157 die
"unknown daemons:${RESULT}; choose from: ${DAEMONS}."
161 for d
in ${STOP_DAEMONS}
163 pidfile
=${STATEDIR}/${d}.pid
164 if [ -f "${pidfile}" -o -n "$(pidof ${d})" ]
166 stop_daemons
="${stop_daemons}${d} "
167 elif [ -n "${ARG_DAEMONS}" ]
169 echo "${ME}: found no ${d} process running."
172 STOP_DAEMONS
=${stop_daemons}
178 for d
in $STOP_DAEMONS
180 echo -n "${ME}: Stopping ${d} ... "
181 pidfile
=${STATEDIR}/${d}.pid
182 if [ -f "${pidfile}" ]
184 file_pid
=$
(cat ${pidfile})
185 if [ -z "${file_pid}" ]
187 echo -n "no pid file entry found ... "
191 echo -n "no pid file found ... "
193 proc_pid
=$
(pidof
${d})
194 if [ -z "${proc_pid}" ]
196 echo -n "found no ${d} process running ... "
202 count
=$
((${count}+1))
205 echo -n "killed ${p} ... "
207 echo -n "failed to kill ${p} ... "
209 [ "${p}" = "${file_pid}" ] \
210 || notinpidfile
="${notinpidfile} ${p}"
213 ||
echo -n "WARNING: ${count} ${d} processes were found running ... "
214 for n
in ${notinpidfile}
216 echo -n "WARNING: process ${n} was not in pid file ... "
220 survivors
=$
(pidof
${d})
221 while [ -n "${survivors}" ]
224 count
=$
((${count}+1))
225 survivors
=$
(pidof
${d})
226 [ -z "${survivors}" -o ${count} -gt 5 ] && break
227 for p
in ${survivors}
234 survivors
=$
(pidof
${d})
235 [ -n "${survivors}" ] && \
236 if kill -KILL ${survivors}
238 echo -n "KILLed ${survivors} ... "
240 echo -n "failed to KILL ${survivors} ... "
243 survivors
=$
(pidof
${d})
244 if [ -z "${survivors}" ]
247 if [ -f "${pidfile}" ]
250 ||
echo -n " Failed to remove pidfile."
253 echo -n "failed to stop ${survivors} - giving up."
254 if [ "${survivors}" != "${file_pid}" ]
256 if echo "${survivors}" > ${pidfile}
258 chown quagga
:quagga
${pidfile}
259 echo -n " Wrote ${survivors} to pidfile."
261 echo -n " Failed to write ${survivors} to pidfile."
270 if [ -n "$START_DAEMONS" ]
273 || quit
"${ME}: no config directory ${CONFDIR} - exiting."
274 chown
-R quagga
:quagga
${CONFDIR}
275 [ -d ${STATEDIR} ] || mkdir
-p ${STATEDIR} \
276 || die
"${ME}: could not create state directory ${STATEDIR} - exiting."
277 chown
-R quagga
:quagga
${STATEDIR}
279 for d
in $START_DAEMONS
281 echo -n "${ME}: Starting ${d} ... "
282 proc_pid
=$
(pidof
${d})
283 pidfile
=${STATEDIR}/${d}.pid
285 if [ -f "${pidfile}" ]
287 file_pid
=$
(cat ${pidfile})
288 if [ -n "${file_pid}" ]
290 echo -n "found old pid file entry ${file_pid} ... "
293 if [ -n "${proc_pid}" ]
295 echo -n "found ${d} running (${proc_pid}) - skipping ${d}."
296 if [ "${proc_pid}" != "${file_pid}" ]
298 if echo "${proc_pid}" > ${pidfile}
300 chown quagga
:quagga
${pidfile}
301 echo -n " Wrote ${proc_pid} to pidfile."
303 echo -n " Failed to write ${proc_pid} to pidfile."
306 elif rm -f "${pidfile}"
308 if [ "${d}" = "watchquagga" ]
311 ${WATCHQUAGGA_FLAGS} \
312 "${WATCHQUAGGA_CMD}" \
313 ${WATCHQUAGGA_DAEMONS})
316 $
("${BINDIR}/${d}" ${DAEMON_FLAGS})
326 echo -n " failed to remove pidfile.
"