apccontrol.j2 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #!/usr/bin/sh
  2. # {{ ansible_managed }}
  3. #
  4. # Copyright (C) 1999-2002 Riccardo Facchetti <riccardo@master.oasi.gpa.it>
  5. #
  6. # for apcupsd release 3.14.14 (31 May 2016) - redhat
  7. #
  8. # platforms/apccontrol. Generated from apccontrol.in by configure.
  9. #
  10. # Note, this is a generic file that can be used by most
  11. # systems. If a particular system needs to have something
  12. # special, start with this file, and put a copy in the
  13. # platform subdirectory.
  14. #
  15. #
  16. # These variables are needed for set up the autoconf other variables.
  17. #
  18. prefix=/usr
  19. exec_prefix=/usr
  20. APCPID=/var/run/apcupsd.pid
  21. APCUPSD=/sbin/apcupsd
  22. SHUTDOWN=/usr/sbin/shutdown
  23. SCRIPTSHELL=/usr/bin/sh
  24. SCRIPTDIR=/etc/apcupsd
  25. WALL=wall
  26. if [ -f $SCRIPTDIR/config ]; then . $SCRIPTDIR/config ; fi
  27. #
  28. # Concatenate all output from this script to the events file
  29. # Note, the following kills the script in a power fail situation
  30. # where the disks are mounted read-only.
  31. # exec >>/var/log/apcupsd.events 2>&1
  32. #
  33. # This piece is to substitute the default behaviour with your own script,
  34. # perl, or C program.
  35. # You can customize every single command creating an executable file (may be a
  36. # script or a compiled program) and calling it the same as the $1 parameter
  37. # passed by apcupsd to this script.
  38. #
  39. # After executing your script, apccontrol continues with the default action.
  40. # If you do not want apccontrol to continue, exit your script with exit
  41. # code 99. E.g. "exit 99".
  42. #
  43. # WARNING: the apccontrol file will be overwritten every time you update your
  44. # apcupsd, doing `make install'. Your own customized scripts will _not_ be
  45. # overwritten. If you wish to make changes to this file (discouraged), you
  46. # should change apccontrol.sh.in and then rerun the configure process.
  47. #
  48. if [ -f ${SCRIPTDIR}/${1} -a -x ${SCRIPTDIR}/${1} ]
  49. then
  50. ${SCRIPTDIR}/${1} ${2} ${3} ${4}
  51. # exit code 99 means he does not want us to do default action
  52. if [ $? = 99 ] ; then
  53. exit 0
  54. fi
  55. fi
  56. case "$1" in
  57. killpower)
  58. echo "Apccontrol doing: ${APCUPSD} --killpower on UPS ${2}" | ${WALL}
  59. sleep 10
  60. ${APCUPSD} --killpower
  61. echo "Apccontrol has done: ${APCUPSD} --killpower on UPS ${2}" | ${WALL}
  62. ;;
  63. commfailure)
  64. echo "Warning communications lost with UPS ${2}" | ${WALL}
  65. ;;
  66. commok)
  67. echo "Communications restored with UPS ${2}" | ${WALL}
  68. ;;
  69. #
  70. # powerout, onbattery, offbattery, mainsback events occur
  71. # in that order.
  72. #
  73. powerout)
  74. ;;
  75. onbattery)
  76. echo "Power failure on UPS ${2}. Running on batteries." | ${WALL}
  77. ;;
  78. offbattery)
  79. echo "Power has returned on UPS ${2}..." | ${WALL}
  80. ;;
  81. mainsback)
  82. if [ -f /etc/apcupsd/powerfail ] ; then
  83. printf "Continuing with shutdown." | ${WALL}
  84. fi
  85. ;;
  86. failing)
  87. echo "Battery power exhausted on UPS ${2}. Doing shutdown." | ${WALL}
  88. ;;
  89. timeout)
  90. echo "Battery time limit exceeded on UPS ${2}. Doing shutdown." | ${WALL}
  91. ;;
  92. loadlimit)
  93. echo "Remaining battery charge below limit on UPS ${2}. Doing shutdown." | ${WALL}
  94. ;;
  95. runlimit)
  96. echo "Remaining battery runtime below limit on UPS ${2}. Doing shutdown." | ${WALL}
  97. ;;
  98. doreboot)
  99. echo "UPS ${2} initiating Reboot Sequence" | ${WALL}
  100. ${SHUTDOWN} -r now "apcupsd UPS ${2} initiated reboot"
  101. ;;
  102. doshutdown)
  103. echo "UPS ${2} initiated Shutdown Sequence" | ${WALL}
  104. ${SHUTDOWN} -h -H now "apcupsd UPS ${2} initiated shutdown"
  105. ;;
  106. annoyme)
  107. echo "Power problems with UPS ${2}. Please logoff." | ${WALL}
  108. ;;
  109. emergency)
  110. echo "Emergency Shutdown. Possible battery failure on UPS ${2}." | ${WALL}
  111. ;;
  112. changeme)
  113. echo "Emergency! Batteries have failed on UPS ${2}. Change them NOW" | ${WALL}
  114. ;;
  115. remotedown)
  116. echo "Remote Shutdown. Beginning Shutdown Sequence." | ${WALL}
  117. ;;
  118. startselftest)
  119. ;;
  120. endselftest)
  121. ;;
  122. battdetach)
  123. ;;
  124. battattach)
  125. ;;
  126. *) echo "Usage: ${0##*/} command"
  127. echo " warning: this script is intended to be launched by"
  128. echo " apcupsd and should never be launched by users."
  129. exit 1
  130. ;;
  131. esac