diff --git a/bundles/wol-sleeper/files/suspend_if_idle b/bundles/wol-sleeper/files/suspend_if_idle index d33f65c..c3b50fb 100644 --- a/bundles/wol-sleeper/files/suspend_if_idle +++ b/bundles/wol-sleeper/files/suspend_if_idle @@ -2,15 +2,19 @@ UPTIME=$(cat /proc/uptime | cut -d. -f1) MIN_UPTIME=$(expr 60 \* 30) -if [[ $UPTIME -lt $MIN_UPTIME ]] +if [[ "$UPTIME" -lt "$MIN_UPTIME" ]] then echo "ABORT: uptime ($UPTIME) lower than min ($MIN_UPTIME)" exit 0 fi +MY_SERVICE="$2" for SERVICE in $(systemctl list-timers --no-pager --no-legend --state active -o json | jq -r '.[] | .activates') do - if systemctl is-active "$SERVICE" --quiet + if [[ "$SERVICE" = "$MY_SERVICE" ]] + then + continue + elif systemctl is-active "$SERVICE" --quiet then echo "ABORT: service $SERVICE is running by timer" exit 0 @@ -18,13 +22,13 @@ do done LOGINS=$(who -u | grep pts\/ | wc -l) -if ! [[ $LOGINS =~ "^0$" ]] +if ! [[ "$LOGINS" =~ "^0$" ]] then echo "ABORT: $LOGINS user logins" exit 0 fi -if [[ $1 = now ]] +if [[ "$1" = now ]] then echo "SESPENDING" sleep 10 diff --git a/bundles/wol-sleeper/metadata.py b/bundles/wol-sleeper/metadata.py index 849ada7..6ac72b6 100644 --- a/bundles/wol-sleeper/metadata.py +++ b/bundles/wol-sleeper/metadata.py @@ -4,10 +4,11 @@ from ipaddress import ip_interface 'systemd-timers/suspend-if-idle', ) def timer(metadata): + name = 'suspend-if-idle'# return { 'systemd-timers': { - 'suspend-if-idle': { - 'command': '/opt/suspend_if_idle now', + name: { + 'command': f'/opt/suspend_if_idle now {name}.service', 'when': 'minutely', }, },