improve wake on lan
This commit is contained in:
parent
9ff8dce802
commit
8a13421577
3 changed files with 31 additions and 9 deletions
|
@ -22,7 +22,7 @@ def systemd(metadata):
|
|||
'Persistent': config.get('persistent', False),
|
||||
'Unit': f'{name}.service',
|
||||
},
|
||||
},
|
||||
},
|
||||
f'{name}.service': {
|
||||
'Unit':{
|
||||
'Description': f'{name} timer service',
|
||||
|
@ -37,9 +37,11 @@ def systemd(metadata):
|
|||
})
|
||||
if config.get('working_dir'):
|
||||
units[f'{name}.service']['Service']['WorkingDirectory'] = config['working_dir']
|
||||
|
||||
if config.get('success_exit_status'):
|
||||
units[f'{name}.service']['Service']['SuccessExitStatus'] = config['success_exit_status']
|
||||
|
||||
services[f'{name}.timer'] = {}
|
||||
|
||||
|
||||
return {
|
||||
'systemd': {
|
||||
'units': units,
|
||||
|
|
|
@ -17,7 +17,7 @@ MIN_UPTIME=$(expr 60 \* 15)
|
|||
if [[ "$UPTIME" -lt "$MIN_UPTIME" ]]
|
||||
then
|
||||
echo "ABORT: uptime of ${UPTIME}s is lower than minimum of ${MIN_UPTIME}s"
|
||||
exit 0
|
||||
exit 75
|
||||
fi
|
||||
|
||||
# CHECK FOR RUNNING TIMERS
|
||||
|
@ -30,7 +30,7 @@ do
|
|||
elif systemctl is-active "$SERVICE" --quiet
|
||||
then
|
||||
echo "ABORT: service $SERVICE is running by timer"
|
||||
exit 0
|
||||
exit 75
|
||||
fi
|
||||
done
|
||||
|
||||
|
@ -40,7 +40,7 @@ LOGINS=$(netstat -tnpa | grep 'ESTABLISHED.*sshd' | tr -s ' ' | cut -d' ' -f5,7-
|
|||
if ! [[ -z "$LOGINS" ]]
|
||||
then
|
||||
echo "ABORT: users logged in: $LOGINS"
|
||||
exit 0
|
||||
exit 75
|
||||
fi
|
||||
|
||||
# SUSPEND!
|
||||
|
@ -48,8 +48,26 @@ fi
|
|||
if [[ "$1" = check ]]
|
||||
then
|
||||
echo "WOULD SESPEND"
|
||||
exit 0
|
||||
else
|
||||
echo "SESPENDING AFTER TIMEOUT"
|
||||
|
||||
for i in 1 2 3 4 5 6
|
||||
do
|
||||
echo "TIMEOUT ${i} success"
|
||||
sleep 10
|
||||
|
||||
# check if condition is still met
|
||||
if "$0" check
|
||||
then
|
||||
continue
|
||||
else
|
||||
echo "SESPENSION ABORTED"
|
||||
exit 75
|
||||
fi
|
||||
done
|
||||
|
||||
echo "SESPENDING"
|
||||
sleep 60
|
||||
systemctl suspend
|
||||
exit 0
|
||||
fi
|
||||
|
|
|
@ -6,6 +6,7 @@ defaults = {
|
|||
'packages': {
|
||||
'jq': {},
|
||||
'ethtool': {},
|
||||
'net-tools': {},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -20,6 +21,7 @@ def timer(metadata):
|
|||
'suspend-if-idle': {
|
||||
'command': f'suspend_if_idle',
|
||||
'when': 'minutely',
|
||||
'success_exit_status': '75',
|
||||
'env': {
|
||||
'THIS_SERVICE': 'suspend-if-idle.service',
|
||||
},
|
||||
|
@ -35,7 +37,7 @@ def wake_command(metadata):
|
|||
waker_hostname = repo.get_node(metadata.get('wol-sleeper/waker')).hostname
|
||||
mac = metadata.get(f"network/{metadata.get('wol-sleeper/network')}/mac")
|
||||
ip = ip_interface(metadata.get(f"network/{metadata.get('wol-sleeper/network')}/ipv4")).ip
|
||||
|
||||
|
||||
return {
|
||||
'wol-sleeper': {
|
||||
'wake_command': f"ssh -o StrictHostKeyChecking=no wol@{waker_hostname} 'wakeonlan {mac} && while ! ping {ip} -c1 -W3; do true; done'",
|
||||
|
@ -49,7 +51,7 @@ def wake_command(metadata):
|
|||
)
|
||||
def systemd(metadata):
|
||||
interface = metadata.get(f"network/{metadata.get('wol-sleeper/network')}/interface")
|
||||
|
||||
|
||||
return {
|
||||
'systemd': {
|
||||
'units': {
|
||||
|
|
Loading…
Reference in a new issue