Project

General

Profile

Change Wakeup-script to use systemd

Added by Tim Lord over 8 years ago

Hi,

first of all: Not a native english speaker, not a Linux-Pro :-)

I've got a problem I can't solve alone. My Setup: DVB-Recordingserver, Ubuntu Mate 16.04 LTS (there's a reason for not using a server version), Digital Devices Cine S2.

What I want the system to do is:

-sleep by default

-wake up when kodi clients power up and stay awake as long as they're online

-wake up when a recording is scheduled and stay awake until recording is done.

-stay awake when a client has started a recording...even if the client is powered down while recording in progress (should be the same as the point above)

It was quite a fight getting the system to a point where the DVB-S card would work after wake-up. The pmutils-scripts I've found caused nothing but problems. The only way I got it to work was to use systemd. What I've achieved so far: The system uses a autosuspend script, suspends and wakes up depending on variables it gets from a config-file AND both TVheadend and the Cine S2 work after suspend.

Problem: Since systemd is the only way my setup works, I need a systemd-version of this script:

https://tvheadend.org/projects/tvheadend/wiki/Wakeup (the second one of course)

Could someone help me with this one?


Replies (2)

RE: Change Wakeup-script to use systemd - Added by Tim Lord over 8 years ago

P.S.: that's the autosuspend script I'm using

#!/bin/bash

  1. Source the configuration file
    . /etc/autosuspend.conf
  1. Log system notice
    logit() {
    logger p local0.notice -s - AutoSuspend: $*
    return 0
    }
  1. Look for other CLIENTS in the network
    IsOnline() {
    for i in $*; do
    ping $i -c1
    if [ "$?" == "0" ]; then
    logit "CLIENT $i is still active, auto suspend terminated"
    return 1
    fi
    done
    return 0
    }

IsRunning() {
for i in $*; do
if `pgrep -c $i` > 0 ; then
logit "PROCESS $i still active, auto suspend terminated"
return 1
fi
done
return 0
}

IsDaemonActive() {
for i in $*; do
if `pgrep -c $i` > 1 ; then
logit "DAEMON $i still active, auto suspend terminated"
return 1
fi
done
return 0
}

IsBusy() { # Samba
if [ "$SAMBANETWORK" ]; then
if [ `/usr/bin/smbstatus | grep $SAMBANETWORK | wc -l ` != "0" ]; then
logit "SAMBA connected, auto suspend terminated"
return 1
fi
fi

#daemons that always have one process running
IsDaemonActive $DAEMONS
if [ "$?" "1" ]; then
return 1
fi
#backuppc, wget, wsus, ....
IsRunning $APPLICATIONS
if [ "$?" "1" ]; then
return 1
fi
  1. No Suspend if there are any users logged in
    if wc -l` > 0 ;then
    logit "USERS still connected, auto suspend terminated";
    return 1
    fi
IsOnline $CLIENTS
if [ "$?" == "1" ]; then
return 1
fi
return 0
}

IDLE_FILE="/var/spool/autosuspend_idle_marker"
OFFFILE="/var/spool/autosuspend_off"

  1. turns off the auto suspend
    if [ -e $OFFFILE ]; then
    logit "auto suspend is turned off by existents of $OFFFILE"
    exit 0
    fi

if [ "$AUTO_SUSPEND" = "no" ]; then
logit "auto suspend is turned off in configuration file /etc/autosuspend.conf"
elif [ "$AUTO_SUSPEND" = "yes" ]; then # Check if system is busy now.
IsBusy
if [ "$?" == "0" ]; then # Idle now. Has the system been idle on the previous check?
if [ -e $IDLE_FILE ]; then # Suspend now.
logit "AUTO SUSPEND CAUSED"
rm -f $IDLE_FILE
systemctl suspend
exit 0
else # Mark system as idle for the next check.
touch $IDLE_FILE
logit "marked as idle for next check"
exit 0
fi
else # Busy now. Mark system as busy for the next check.
rm -f $IDLE_FILE
logit "marked as busy for the next check"
exit 0
fi
exit 0

else
logit "misconfiguration. Check /etc/autosuspend.conf"
fi
exit 1

RE: Change Wakeup-script to use systemd - Added by JP T about 8 years ago

Did you find a solution yet?

as an example, I was able to deny standby when samba connections are active. This looks very simple with systemd.

/etc/systemd/system/dontkillsamba.service
[Unit]
Description=Inhibit suspend in case of samba activity
Before=sleep.target

[Service]
Type=oneshot
ExecStart=/bin/sh -c "! smbstatus -nb | tail -n +5 | grep -q '^[0-9]*'" 

[Install]
RequiredBy=sleep.target

but making the pc wakeup on scheduled recordings will be more complicated...

could you please enclose your script in pre tags? reading is difficult.

mh, I will think about how to solve this problem.

maybe something like this:

[Unit]
Description=Inhibit suspend in case of wget running
Before=sleep.target

[Service]
Type=oneshot
ExecStart=pgrep -c wget

[Install]
RequiredBy=sleep.target

    (1-2/2)