freedombone-utils-watchdog 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Watchdog functions to keep systems running even if they crash
  12. # systemd itself may be able to handle this to a large extent
  13. #
  14. # License
  15. # =======
  16. #
  17. # Copyright (C) 2014-2016 Bob Mottram <bob@robotics.uk.to>
  18. #
  19. # This program is free software: you can redistribute it and/or modify
  20. # it under the terms of the GNU Affero General Public License as published by
  21. # the Free Software Foundation, either version 3 of the License, or
  22. # (at your option) any later version.
  23. #
  24. # This program is distributed in the hope that it will be useful,
  25. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. # GNU Affero General Public License for more details.
  28. #
  29. # You should have received a copy of the GNU Affero General Public License
  30. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  31. # name of a script which keeps running processes going even if they crash
  32. WATCHDOG_SCRIPT_NAME="keepon"
  33. function install_watchdog_script {
  34. if grep -Fxq "install_watchdog_script" $COMPLETION_FILE; then
  35. return
  36. fi
  37. echo '#!/bin/bash' > /usr/bin/$WATCHDOG_SCRIPT_NAME
  38. echo 'LOGFILE=/var/log/keepon.log' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
  39. echo 'CURRENT_DATE=$(date)' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
  40. # application specific stuff is added later
  41. chmod +x /usr/bin/$WATCHDOG_SCRIPT_NAME
  42. function_check cron_add_mins
  43. cron_add_mins 1 '/usr/bin/$WATCHDOG_SCRIPT_NAME'
  44. echo 'install_watchdog_script' >> $COMPLETION_FILE
  45. }
  46. # NOTE: deliberately no exit 0