You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
4.1 KiB

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