Jump to content


Photo

Sleep prevention not working


  • Please log in to reply
7 replies to this topic

#1 M1tch OFFLINE  

M1tch

    Member

  • Members
  • 18 posts
  • Local time: 12:55 PM

Posted 11 May 2019 - 08:43 AM

I saw this a few times on the windows server and ended up just setting sleep in the os to 3 hrs.

The Mac appears to do the same I have tried 15 and 30 mins and each time the server sleeps mid stream to a Samsung tv .

Anything else I check ?

#2 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 136081 posts
  • Local time: 07:55 AM

Posted 11 May 2019 - 11:33 AM

Hi, on MacOS we don't currently have any sleep prevention so you'll need to configure it in system settings. It's something we plan to add in the future. Thanks.

#3 M1tch OFFLINE  

M1tch

    Member

  • Members
  • 18 posts
  • Local time: 12:55 PM

Posted 11 May 2019 - 11:57 AM

That would explain it then! Thanks Luke

#4 M1tch OFFLINE  

M1tch

    Member

  • Members
  • 18 posts
  • Local time: 12:55 PM

Posted 18 May 2019 - 03:53 PM

For anyone searching for similar, here is a stop gap that works pretty well until the Emby team add it in the future. I can't take credit I just reused from a cool script from "Parnty" here https://forums.plex....-on-lan/60590/3

 

 

It checks the last 20 lines of the Emby Server log file for "emby/Sessions/Playing/Progress" every 30 secs and uses caffeinate to keep the mac awake.

When it can't see that string the assertion gets removed and the mac sleeps per the system settings.

 

Note: I may try to change this to look for any update to the log file as if emby is updating metadata etc the playing/progress piece gets lost in the noise. If anyone has a better way to approach i'd been keen to hear as i'm no dev..

 

 

1. Create ~/Library/LaunchAgents/embyCaffeinate.plist as follows:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>embyCaffeinate</string>

    <key>ProgramArguments</key>
    <array>
        <string>sh</string>
        <string>-c</string>
        <string>"$HOME/Library/Scripts/embyCaffeinate.sh"</string>
    </array>

    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
</dict>
</plist>

2. Create ~/Library/Scripts/embyCaffeinate.sh as follows:

#!/bin/bash


# Paths
embyLog=~/emby-server/logs/embyserver.txt 
caffLog=~/emby-server/logs/Caffeinate.log

# Kill subprocess on exit
trap '[[ -z "$(jobs -p)" ]] || kill $(jobs -p)' EXIT

# Functions
timestamp()      { date "+%b %d %H:%M:%S"; }
today()          { date "+%d"; }
embyUpdateTime() { stat -f %m "$embyLog" 2>/dev/null; }
embyUserAction() { tail -20 "$embyLog" | \
                   grep "emby/Sessions/Playing/Progress" | \
                   tail -1 2>/dev/null; }

# Init globals
initDay()        { day=$(today); }
initembyState()  { updateTime=$(embyUpdateTime);
                   userAction=$(embyUserAction); }

# Day check
isSameDay()
{
    local myDay=$(today)
    if [ "$myDay" = "$day" ]; then
        return 0
    else
        day=$myDay 
        return 1
    fi
}

# Idle check
isembyIdle()
{
    local myUpdateTime=$(embyUpdateTime)
    if [ -z "$myUpdateTime" ] || \
       [ "$myUpdateTime" = "$updateTime" ]; then
        return 0
    else
        updateTime=$myUpdateTime
        return 1
    fi
}

# Housekeeping check
isembyHousekeeping()
{
    local myUserAction=$(embyUserAction)
    if [ -z "$myUserAction" ] || \
       [ "$myUserAction" = "$userAction" ]; then
        return 0
    else
        userAction=$myUserAction
        return 1
    fi
}

# Wait until user has finished using emby
waitForUser()
{
    initembyState
    while true; do
        echo "$(timestamp) Caffeinating..." >> "$caffLog"

        sleep 120

        if isembyIdle;         then break; fi
        if isembyHousekeeping; then break; fi
    done
}

# Check emby and caffeinate if needed
initDay
initembyState
while true; do
    sleep 30

    # Rotate logs
    if ! isSameDay; then mv "$caffLog" "$caffLog".1 2>/dev/null; fi

    # Check emby
    if isembyIdle; then
        echo "$(timestamp) emby is idle" >> "$caffLog"
    elif isembyHousekeeping; then
        echo "$(timestamp) emby is running background tasks" >> "$caffLog"

    # Caffeinate
    else
        echo "$(timestamp) Caffeinate" >> "$caffLog"
        waitForUser &
        caffeinate -is -w $! 2>/dev/null
        echo "$(timestamp) Caffeinated" >> "$caffLog"

        initembyState
    fi
done

 

3.In Terminal, run the following

chmod a+x ~/Library/Scripts/embyCaffeinate.sh

launchctl load ~/Library/LaunchAgents/embyCaffeinate.plist

Edited by M1tch, 18 May 2019 - 03:54 PM.


#5 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 136081 posts
  • Local time: 07:55 AM

Posted 18 May 2019 - 04:13 PM

Hi, that's great info, thanks !



#6 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 136081 posts
  • Local time: 07:55 AM

Posted 26 May 2019 - 03:11 PM

The beta server has this now if you'd like to help test that:

https://emby.media/c...beta-for-macos/

 

Thanks.



#7 M1tch OFFLINE  

M1tch

    Member

  • Members
  • 18 posts
  • Local time: 12:55 PM

Posted 07 June 2019 - 02:02 PM

The beta server has this now if you'd like to help test that:

https://emby.media/c...beta-for-macos/

 

Thanks.

up for testing - link to beta not working at the moment



#8 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 136081 posts
  • Local time: 07:55 AM

Posted 07 June 2019 - 03:15 PM

We'll have a new one for MacOS up soon. Thanks.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users