SageTV Community  

Go Back   SageTV Community > SageTV Products > SageTV Linux > SageTV for unRAID/Docker

Notices

SageTV for unRAID/Docker Discussion related to SageTV for unRAID/Docker. Questions, issues, problems, suggestions, etc. relating to SageTV for unRAID/Docker should be posted here.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-22-2021, 04:16 PM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,217
Automatically "power on" extenders on docker start

How to use:
  1. Download the two attached files.
  2. Change the Extenders list in the start_extenders.sh file to the IP addresses used by your extenders.
  3. Remove the .txt extensions so that the files both have extensions of .sh.
  4. Look to see if you have a file called /appdata/sagetv/server/sagetv-user-script.sh - if you do see the warning below
  5. Put both of these files in the /appdata/sagetv/server folder.
  6. Start a ssh session to your unRAID server.
  7. Start a bash session in your sagetv docker with "docker exec -it sagetv /bin/bash"
  8. Download the package list with "apt-get update"
  9. Install telnet with "apt-get install telnet"

Warning - if you already have a sagetv-user-script.sh file then you will need to just copy line 2 of the attached version of sagetv-user-script.sh into your existing sagetv-user-script.sh file.

Pre-req: Your extenders should have IP addresses that don't change. This can be done either by setting up a static IP address in the extenders setup pages, or by setting up DHCP reservations in your router's UI.

This thread contains scripts to restart your HD200 and HD300 extenders automatically whenever the SageTV docker starts. This is possible because the SageTV docker looks for a script file called sagetv-user-script.sh and it runs this script as part of the docker start process. The script in this threadn starts a telnet session on each SageTV extender and "turns on" the extender.

Note that telnet is not installed in the sagetv docker (this may change in the future), so you need to manually install telnet in the docker. You will need to redo this if your SageTV version is updated or you install a new version of the docker.

There is a slight trick needed here as SageTV waits for this script to exit before contiuing to start up, but the extenders can't connect to the SageTV server unless it is up and running. Therefore you have to use this script to call another script and have it run asynchronously, which you can do by putting an & after the script name.

This script sends some output to your sagetv log file - I have posted a sample of what you will see below. Note that the script waits 30 seconds for SageTV to get up and running before turning on the extenders.

Here is the sagetv-user-script.sh script
Code:
#!/bin/bash
bash /opt/sagetv/server/start_extenders.sh &
Here is the start_extenders.sh script - This is the script that actually does all of the work. It loops through a list of extenders (by IP address). Replace the list in the 9th line with your actual extender IP addresses

Code:
#!/bin/bash

echo -e "\n" 
echo "==========================================================" 
echo "Starting all extenders at : " $(date) 
echo "==========================================================" 

# Put the IP addresses of your extenders in the list below
declare -a  Extenders=("192.168.1.48" "192.168.1.50" "192.168.1.51" "192.168.1.52" "192.168.1.56" "192.168.1.58" "192.168.1.59" "192.168.1.143")
sleep 30
# Iterate the string array using for loop
for val in ${Extenders[@]}; do
     { sleep 0.2; echo "root"; sleep 0.2; echo "killall waitpower"; sleep 0.2; }  | telnet $val 
	 echo -e "======================================================\n" 
done
Sample Log output (Some of the lines are from SageTV and not from this script):
Code:
dos2unix: converting file /opt/sagetv/server/sagetv-user-script.sh to Unix format ...

=========================================================
*** Running /etc/my_init.d/90-sagetv...
Starting all extenders at : Mon Mar 22 01:39:41 EDT 2021
==========================================================
Changing to SageTV directory /opt/sagetv/server
cat: activkey: No such file or directory
*** Running /etc/rc.local...
Executing pre-scripts
*** Booting runit daemon...
*** Runit started as PID 96
Starting server mode
./startsagecore: line 54: /var/run/sagetv.pid: Permission denied
Mar 22 01:39:44 Hoylake syslog-ng[106]: syslog-ng starting up; version='3.5.6'

Main is starting
Trying 192.168.1.48...
Connected to 192.168.1.48.
Escape character is '^]'.

tango3 login: root
tango3[~]# killall waitpower
Connection closed by foreign host.
tango3[~]# ======================================================

Trying 192.168.1.50...
Connected to 192.168.1.50.
Escape character is '^]'.

tango3 login: root
tango3[~]# killall waitpower
Connection closed by foreign host.
tango3[~]# ======================================================

Trying 192.168.1.51...
Connected to 192.168.1.51.
Escape character is '^]'.

tango3 login: root
tango3[~]# killall waitpower
Connection closed by foreign host.
tango3[~]# ======================================================

Trying 192.168.1.52...
Connected to 192.168.1.52.
Escape character is '^]'.

tango3 login: root
tango3[~]# killall waitpower
Connection closed by foreign host.
tango3[~]# ======================================================

Trying 192.168.1.56...
Connected to 192.168.1.56.
Escape character is '^]'.

STP-HD200 login: root
killall waitpower
STP-HD200[/tmp]# killall waitpower
Connection closed by foreign host.
STP-HD200[/tmp]# ======================================================

Trying 192.168.1.58...
Connected to 192.168.1.58.
Escape character is '^]'.

STP-HD200 login: root
STP-HD200[/tmp]# killall waitpower
killall: waitpower: no process killed

Connection closed by foreign host.
STP-HD200[/tmp]# ======================================================

Trying 192.168.1.59...
Connected to 192.168.1.59.
Escape character is '^]'.

STP-HD200 login: root
STP-HD200[/tmp]# killall waitpower
killall: waitpower: no process killed

Connection closed by foreign host.
STP-HD200[/tmp]# ======================================================

Trying 192.168.1.143...
Connected to 192.168.1.143.
Escape character is '^]'.

tango3 login: root
tango3[~]# killall waitpower
Connection closed by foreign host.
tango3[~]# ======================================================
Attached Files
File Type: txt sagetv-user-script.sh.txt (58 Bytes, 63 views)
File Type: txt start_extenders.sh.txt (664 Bytes, 64 views)
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
  #2  
Old 12-02-2021, 11:48 AM
KeithAbbott KeithAbbott is online now
Sage Icon
 
Join Date: Oct 2009
Location: Southeastern Michigan
Posts: 1,239
Now that stuckless has added the telnet client into the SageTV docker image, I have taken the script(s) that wayner originally created and made some modifications. Only a single script (/appdata/sagetv/server/sagetv-user-script.sh) is needed, since there is an inline function that is called asynchronously that sleeps for 30 seconds and then issues the commands to start up the extenders.

Code:
#!/bin/bash

# Define inline function to start all extenders
start_extenders () {

    # Put the IP addresses of your extenders in the list below
    declare -a Extenders=("192.168.1.50" "192.168.1.51" "192.168.1.52" "192.168.1.53" "192.168.1.54" "192.168.1.55" "192.168.1.56" "192.168.1.57" "192.168.1.58" "192.168.1.59")

    # Sleep for 30 seconds, to allow time for SageTV to start before attempting to power-on extenders
    sleep 30

    write_log_entry "=========================================================="
    write_log_entry "Starting all extenders"
    write_log_entry "=========================================================="

    # Iterate the string array using for loop
    for Extender in ${Extenders[@]}; do

        # Attempt to start extender
        { sleep 0.2; echo "root"; sleep 0.2; echo "killall waitpower"; sleep 0.2; } | telnet $Extender 1> /tmp/telnet_output 2> /tmp/telnet_errors ; cat /tmp/telnet_output /tmp/telnet_errors 1> /tmp/telnet_output_and_errors

        # Write telnet output and errors (if any) to log file
        while IFS= read -r line; do

            write_log_entry "$line"

        done < /tmp/telnet_output_and_errors

        write_log_entry "=========================================================="

    done

    # Delete all temporary files created from this script
    rm -f /tmp/telnet_*

    # Exit function back to Linux, since this function is called asynchronously
    exit 0

}

# Define function to write entries to log file
write_log_entry () {

    echo -e "$(date +'%F %T.%4N %Z') [${0##*/}] $1"

}

# Mainline processing

write_log_entry "**********************************************************"
write_log_entry "*** Executing startup script"
write_log_entry "**********************************************************"

# Call function asynchronously to start all extenders, while allowing SageTV startup to continue
start_extenders &

write_log_entry "**********************************************************"
write_log_entry "*** Exiting startup script"
write_log_entry "**********************************************************"
btw, if no extender is found for a given IP address, it moves on to the next extender in the list. Also, if an extender is being used when the telnet command is issued, the extender is not interrupted (i.e. whatever is being watched does not stop, pause, etc.).

Thanks to wayner for creating the original script(s), it's much easier to modify something that already exists than to create something from scratch.
__________________
Server: MSI Z270 SLI Plus ATX Motherboard, Intel i7-7700T CPU, 32GB Memory, unRAID 6.9.2, SageTV (java11) & OpenDCT Dockers
Tuners: 2 x SiliconDust HDHomeRun Prime Cable TV Tuners, SiliconDust HDHomeRun CONNECT 4K OTA Tuner
Clients: Multiple HD300 Extenders, Multiple Fire TV Stick 4K Max w/MiniClient
Miscellaneous: Multiple Sony RM-VLZ620 Universal Remote Controls
Reply With Quote
  #3  
Old 12-02-2021, 11:48 PM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,217
Good work. It is nice to have the extenders reset and to have them powered up and ready to go at all times.

I haven't upgraded to the newer docker versions as I am on the 6.4.1 version of unRAID so if I upgrade then I have a bunch of work to figure out how to get the DVB version of unRAID to work as I need that to record from my HD-PVRs.

The old DVB edition plugin for unRAID stopped being supported due to a fight between the guy that developed it and the unRAID. But there is a new way to do this, it may even be incorporated into the core of unRAID, but I don't want to try this and not have it work and then be stock with not being able to record in SageTV. So I will build a new server soon and redo the SageTV installation from scratch.
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't connect to unraid docker, no "TV" Menu Item dealsdyker SageTV for unRAID/Docker 7 09-30-2017 09:30 AM
"Backdrops" "SageTV" "Covers" folders - what's creating them mp328 Sage My Movies 4 09-20-2010 05:31 PM
"Set defaults" for Series forgets "Keep"/"Auto-delete" setting maxpower SageMC Custom Interface 9 05-14-2008 09:44 PM


All times are GMT -6. The time now is 08:59 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.