MT#57556 Prompt for reboot/halt only in interactive mode

With our newer Grml-Sipwise ISO (v2023-06-01) being based on
Debian/bookworm and recent Grml packages, our automated deployment
suddenly started to fail for us:

| +04:28:12 (netscript.grml:2453):  echo 'Successfully finished deployment process [Fri Jun  2 04:28:12 UTC 2023 - running 576 seconds]'
| ++04:28:12 (netscript.grml:2455):  get_deploy_status
| ++04:28:12 (netscript.grml:95): get_deploy_status():  '[' -r /srv/deployment//status ']'
| ++04:28:12 (netscript.grml:96): get_deploy_status():  cat /srv/deployment//status
| Successfully finished deployment process [Fri Jun  2 04:28:12 UTC 2023 - running 576 seconds]
| +04:28:12 (netscript.grml:2455):  '[' copylogfiles '!=' error ']'
| +04:28:12 (netscript.grml:2456):  set_deploy_status finished
| +04:28:12 (netscript.grml:103): set_deploy_status():  '[' -n finished ']'
| +04:28:12 (netscript.grml:104): set_deploy_status():  echo finished
| +04:28:12 (netscript.grml:2459):  false
| +04:28:12 (netscript.grml:2463):  status_wait
| +04:28:12 (netscript.grml:329): status_wait():  [[ -n 0 ]]
| +04:28:12 (netscript.grml:329): status_wait():  [[ 0 != 0 ]]
| +04:28:12 (netscript.grml:2466):  false
| +04:28:12 (netscript.grml:2471):  false
| +04:28:12 (netscript.grml:2476):  echo 'Do you want to [r]eboot or [h]alt the system now? (Press any other key to cancel.)'
| Do you want to [r]eboot or [h]alt the system now? (Press any other key to cancel.)
| +04:28:12 (netscript.grml:2477):  unset a
| +04:28:12 (netscript.grml:2478):  read -r a
| ++04:28:12 (netscript.grml:2478):  wait_exit
| ++04:28:12 (netscript.grml:339): wait_exit():  local e_code=1
| ++04:28:12 (netscript.grml:340): wait_exit():  [[ 1 -ne 0 ]]
| ++04:28:12 (netscript.grml:341): wait_exit():  set_deploy_status error
| ++04:28:12 (netscript.grml:103): set_deploy_status():  '[' -n error ']'
| ++04:28:12 (netscript.grml:104): set_deploy_status():  echo error
| ++04:28:12 (netscript.grml:343): wait_exit():  trap '' 1 2 3 6 15 ERR EXIT
| ++04:28:12 (netscript.grml:344): wait_exit():  status_wait
| ++04:28:12 (netscript.grml:329): status_wait():  [[ -n 0 ]]
| ++04:28:12 (netscript.grml:329): status_wait():  [[ 0 != 0 ]]
| ++04:28:12 (netscript.grml:345): wait_exit():  exit 1

As of grml-autoconfig v0.20.3 and newer, the grml-autoconfig systemd service
that invokes the deployment netscript uses `StandardInput=null` instead of
`StandardInput=tty` (see https://github.com/grml/grml/issues/176).

Thanks to this, a logic error in our deployment script showed up.  We
exit the script in interactive mode, though only *afterwards* prompting
for reboot/halt with `read -r a` - which of course fails if stdin is
missing. As a result, we end up in our signal handler `trap 'wait_exit;'
1 2 3 6 15 ERR EXIT` and then fail the deployment.

So instead prompt for "Do you want to [r]eboot or [h]alt ..." *only* in
interactive mode, and while at it drop the "if "$INTERACTIVE" ; then
exit 0 ; fi" so the prompt is actually presented to the user.

Change-Id: Ia89beaf3c446f3701cc30ab21cfdff7b5808a6d3
mr11.4
Michael Prokop 2 years ago
parent 98d11bfc28
commit 2ad306c465

@ -2456,10 +2456,6 @@ if [ "$(get_deploy_status)" != "error" ] ; then
set_deploy_status "finished"
fi
if "$INTERACTIVE" ; then
exit 0
fi
status_wait
# do not prompt when running in automated mode
@ -2473,21 +2469,23 @@ if "$HALT" ; then
systemctl poweroff
fi
echo "Do you want to [r]eboot or [h]alt the system now? (Press any other key to cancel.)"
unset a
read -r a
case "${a,,}" in
r)
echo "Rebooting system as requested."
systemctl reboot
;;
h)
echo "Halting system as requested."
systemctl poweroff
;;
*)
echo "Not halting system as requested. Please do not forget to reboot."
if "$INTERACTIVE" ; then
echo "Do you want to [r]eboot or [h]alt the system now? (Press any other key to cancel.)"
unset a
read -r a
case "${a,,}" in
r)
echo "Rebooting system as requested."
systemctl reboot
;;
esac
h)
echo "Halting system as requested."
systemctl poweroff
;;
*)
echo "Not halting system as requested. Please do not forget to reboot."
;;
esac
fi
## END OF FILE #################################################################1

Loading…
Cancel
Save