cron.reboot 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/bin/bash
  2. # No way I try to deal with a crippled sh just for POSIX foo.
  3. # Copyright (C) 2009 Joerg Jaspert <joerg@debian.org>
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License as
  7. # published by the Free Software Foundation; version 2.
  8. #
  9. # This program is distributed in the hope that it will be useful, but
  10. # WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. # exit on errors
  18. set -e
  19. set -o pipefail
  20. # make sure to only use defined variables
  21. set -u
  22. # ERR traps should be inherited from functions too. (And command
  23. # substitutions and subshells and whatnot, but for us the functions is
  24. # the important part here)
  25. set -E
  26. # We sleep a while here, as cron - and as such @reboot jobs like this
  27. # one - are started pretty early during boot. With parts of the system
  28. # still missing, most noticable for us is a not-yet-started postgres...
  29. sleep 75
  30. # import the general variable set.
  31. export SCRIPTVARS=/srv/ftp-master.debian.org/dak/config/debian/vars
  32. . $SCRIPTVARS
  33. # common functions are "outsourced"
  34. . "${configdir}/common"
  35. # usually we are not using debug logs. Set to 1 if you want them.
  36. DEBUG=0
  37. # our name
  38. PROGRAM="dinstall_reboot"
  39. # where do we want mails to go? For example log entries made with error()
  40. if [[ ${HOSTNAME} != fasolo ]]; then
  41. # Not our ftpmaster host
  42. MAILTO=${MAILTO:-"root"}
  43. else
  44. # Yay, ftpmaster
  45. MAILTO=${MAILTO:-"ftpmaster@debian.org"}
  46. fi
  47. # Marker for dinstall start
  48. DINSTALLSTART="${lockdir}/dinstallstart"
  49. # Marker for dinstall end
  50. DINSTALLEND="${lockdir}/dinstallend"
  51. set +e
  52. starttime=$(/usr/bin/stat -c %Z "${DINSTALLSTART}")
  53. endtime=$(/usr/bin/stat -c %Z "${DINSTALLEND}")
  54. set -e
  55. if [ ${endtime} -gt ${starttime} ]; then
  56. # Great, last dinstall run did seem to end without trouble, no need to rerun
  57. log "Last dinstall run did end without trouble, not rerunning"
  58. exit 0
  59. else
  60. # Hrm, it looks like we did not successfully end the last run.
  61. # This either means dinstall did abort due to an error, or we had a reboot
  62. # No way to tell, so lets restart and see what happens.
  63. # Make sure we are not fooled by some random touching of the files, only
  64. # really restart if we have the first stage stampfile there, indicating that
  65. # dinstall got started
  66. if [ -f "${stagedir}/savetimestamp" ]; then
  67. log "Seems we have to restart a dinstall run after reboot"
  68. ${configdir}/cronscript dinstall
  69. fi
  70. fi