maybe_wall() {
wall_counter=$((wall_counter-1))
if [ "$wall_counter" -le 0 ]; then
- if [ "$host" = 1 ]; then
+ if [ "$halt" = 1 ]; then
echo "System will halt for $reason when buildd has stopped" | wall
else
echo "System will reboot for $reason when buildd has stopped" | wall
echo
fi
- if [ "$host" = 1 ]; then
- /sbin/shutdown -p 15 "$reason"
+ if grep 'waiting-for-clean-shutdown' ~buildd/NO-DAEMON-PLEASE > /dev/null; then
+ sudo -u buildd sh -c 'echo delete-on-boot > ~buildd/NO-DAEMON-PLEASE'
+ fi
+ if [ "$halt" = 1 ]; then
+ /sbin/shutdown -h 1 "$reason"
else
- /sbin/shutdown -p 15 "$reason"
+ /sbin/shutdown -r 1 "$reason"
fi
}
fi
if ! test -e ~buildd/NO-DAEMON-PLEASE; then
- echo "Touching ~buildd/NO-DAEMON-PLEASE ~buildd/EXIT-DAEMON-PLEASE"
- sudo -u buildd touch ~buildd/NO-DAEMON-PLEASE ~buildd/EXIT-DAEMON-PLEASE
- sudo -u buildd sh -c 'echo delete-on-boot > ~buildd/NO-DAEMON-PLEASE'
- sudo chgrp -v adm ~buildd/NO-DAEMON-PLEASE
-
- echo "Sending HUP to buildd"
- sudo -u buildd kill -HUP `sudo cat ~buildd/build/buildd.pid`
+ if [ -e ~buildd/build/buildd.pid ] ; then
+ echo "Touching ~buildd/NO-DAEMON-PLEASE ~buildd/EXIT-DAEMON-PLEASE"
+ sudo -u buildd touch ~buildd/NO-DAEMON-PLEASE ~buildd/EXIT-DAEMON-PLEASE
+ sudo -u buildd sh -c 'echo waiting-for-clean-shutdown > ~buildd/NO-DAEMON-PLEASE'
+ sudo chgrp -v adm ~buildd/NO-DAEMON-PLEASE
+
+ echo "Sending HUP to buildd"
+ sudo -u buildd kill -HUP `sudo cat ~buildd/build/buildd.pid`
+ else
+ echo "no-daemon-please does not exist, but there is no buildd.pid file either"
+ if pgrep -u buildd -x buildd ; then
+ echo "But there is a buildd running. Bad?"
+ exit 3
+ fi
+ fi
else
echo "no-daemon-please already exists"
fi