wol suspend if idle
This commit is contained in:
parent
4e56ba6da0
commit
cfee1d74b0
3 changed files with 53 additions and 0 deletions
bundles/wol-sleeper
35
bundles/wol-sleeper/files/suspend_if_idle
Normal file
35
bundles/wol-sleeper/files/suspend_if_idle
Normal file
|
@ -0,0 +1,35 @@
|
|||
#!/bin/bash
|
||||
|
||||
UPTIME=$(cat /proc/uptime | cut -d. -f1)
|
||||
MIN_UPTIME=$(expr 60 \* 30)
|
||||
if [[ $UPTIME -lt $MIN_UPTIME ]]
|
||||
then
|
||||
echo "ABORT: uptime ($UPTIME) lower than min ($MIN_UPTIME)"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
for SERVICE in $(systemctl list-timers --no-pager --no-legend --state active -o json | jq -r '.[] | .activates')
|
||||
do
|
||||
if systemctl is-active "$SERVICE" --quiet
|
||||
then
|
||||
echo "ABORT: service $SERVICE is running by timer"
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
|
||||
LOGINS=$(who -u | grep pts\/ | wc -l)
|
||||
if ! [[ $LOGINS =~ "^0$" ]]
|
||||
then
|
||||
echo "ABORT: $LOGINS user logins"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ $1 = now ]]
|
||||
then
|
||||
echo "SESPENDING"
|
||||
sleep 10
|
||||
systemctl suspend
|
||||
else
|
||||
echo "WOULD SESPEND"
|
||||
sleep 300
|
||||
fi
|
|
@ -1,3 +1,9 @@
|
|||
waker_node = repo.get_node(node.metadata.get('wol-sleeper/waker'))
|
||||
if not waker_node.has_bundle('wol-waker'):
|
||||
raise Exception(f'waker node {waker_node.name} does not have bundle wol-waker')
|
||||
|
||||
files = {
|
||||
'/opt/suspend_if_idle': {
|
||||
'mode': '550',
|
||||
},
|
||||
}
|
||||
|
|
|
@ -1,5 +1,17 @@
|
|||
from ipaddress import ip_interface
|
||||
|
||||
@metadata_reactor.provides(
|
||||
'systemd-timers/suspend-if-idle',
|
||||
)
|
||||
def timer(metadata):
|
||||
return {
|
||||
'systemd-timers': {
|
||||
'suspend-if-idle': {
|
||||
'command': '/opt/suspend_if_idle now',
|
||||
'when': 'minutely',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@metadata_reactor.provides(
|
||||
'wol-sleeper/wake_command',
|
||||
|
|
Loading…
Reference in a new issue