File: //usr/syno/lib/systemd/scripts/syno-upsmon.sh
#!/bin/sh
. /usr/syno/bin/synoupscommon
ForceStopUpsmon() {
ShowLog "Stop UPS Monitor timeout, Force stop UPS Monitor"
killall -9 upsmon > /dev/null 2>&1
killall -9 upssched > /dev/null 2>&1
sleep 3
}
WaitStopUpsmon() {
for i in `seq 1 1 3`; do
sleep 3
local P_COUNT=`ps -aux |grep -E "(/usr/sbin/upsmon|/usr/sbin/upssched)"|grep -cv grep`
if [ 0 -eq $P_COUNT ]; then
return 0
fi
done
ForceStopUpsmon
return 255
}
StopUpsmon() {
ShowLog "Stop UPS Monitor"
killall upsmon > /dev/null 2>&1
killall upssched > /dev/null 2>&1
#we need to check the process stopped, in some low level DS, it sometimes costs much time
WaitStopUpsmon
return 0
}
{
flock -x 58
case "$1" in
start)
StartClient
;;
stop)
StopUpsmon
;;
restart)
StopUpsmon
StartClient
;;
esac
flock -u 58
} 58<>$UPS_LOCK