2015-11-30
The new idle.py is now a part of the LinHES 8.3 installation and upgrade.
(NO more any change in idle.py !!)
After update the LinHES-system (8.3-15 -> 8.3-19) the new version is online.
solution is in posting #4
THIS IS FOR INFORMATION ONLY
Hi,
I use my Mythbackend server as a Samba server to share my music and picture files for connected windows client PCs. On my windows machine I have an wake-on-lan batch file (WolCmd.exe) that can remotely start the Mythbackend server.
Mythwelcome and the LinHES script “/usr/LH/bin/idle.py” without some modifications have no check for active windows client connection.
I have basic experience in Linux shell scripting, but not in python programming language. But I found a solution to check for active samba connections.
Requirement are LinHES-system 8.2-5 mythtv 0.27.4-3 and
/usr/LH/bin/idle.py from Nov 20 17:27, 12947 bytes (md5sum 69ecfe682f1b61c2c4c95d890b9f523c)
You can do the following steps:
1) Make a copy of the file /usr/LH/bin/idle.py
2) Cut and Replace the function “userlogins_check”
3) Save the change in a NEW file /usr/LH/bin/idle-samba.py
4) Test the script with an active samba share
5) Make a backup copy of the file /usr/LH/bin/mythwelcome-config.py
6) Modify and execute the file /usr/LH/bin/mythwelcome-config.py
7) Check in mythtv-setup the new setting of wake up
This are the details:
1) Make a copy of the file /usr/LH/bin/idle.py
Code:
cp -a -v /usr/LH/bin/idle.py /usr/LH/bin/idle-samba.py
‘/usr/LH/bin/idle.py’ -> ‘/usr/LH/bin/idle-samba.py’
2) Cut and Replace the function “userlogins_check” in the NEW file /usr/LH/bin/idle-samba.py
Cut this lines 185-202
Code:
def userlogins_check(cmdargs):
if (cmdargs.logins):
u=False
msg(cmdargs," Checking for users logged in...")
users=subprocess.check_output("who")
names=([x.split() for x in users.splitlines()])
for i in names:
if (i[0] == "mythtv" and i[4] == "(:0)"):
msg(cmdargs," Ignoring %s %s" %(i[0],i[4]))
else:
msg(cmdargs," User logged in: %s %s" %(i[0],i[4]))
u=True
if u:
return False
else:
return True
else:
return True
Replace and insert this code (Please check that the end of line is LF only (not CR LF) )
Code:
def userlogins_check(cmdargs):
if (cmdargs.logins):
u=False
msg(cmdargs," Checking for users logged in...")
users=subprocess.check_output("who")
names=([x.split() for x in users.splitlines()])
for i in names:
if (i[0] == "mythtv" and i[4] == "(:0)"):
msg(cmdargs," Ignoring %s %s" %(i[0],i[4]))
else:
msg(cmdargs," User logged in: %s %s" %(i[0],i[4]))
u=True
msg(cmdargs," Checking for active samba users....")
samba_status = subprocess.Popen(['sudo','smbstatus'], stdout=subprocess.PIPE)
samba_conn = "Locked files:\n" in samba_status.stdout
if ( samba_conn ):
msg(cmdargs," System is busy -active samba users-")
else:
msg(cmdargs," System is idle -no active samba users-")
if ( u or samba_conn ):
msg(cmdargs," System is busy -active linux user (ssh) or samba users-")
return False
else:
msg(cmdargs," System is idle -no active linux user (ssh) or samba users-")
return True
else:
return True
3) Save the change in the NEW file /usr/LH/bin/idle-samba.py, file listing show:
/usr/LH/bin/idle-samba.py 13547 bytes (md5sum eeb7778b2b0890497ee8c39e655cf57d)
4) Test the script with an active samba share
Open a samba share on your windows machine and open a termial session (ALT X) as a user mythtv
Code:
$ /usr/LH/bin/idle-samba.py -d -l -r -g
Checking system idle...
Checking for users logged in...
Checking for active samba users....
System is busy -active samba users-
System is busy -active linux user (ssh) or samba users-
System is busy.
If you see any python error messages stop here at step 4 and fix this!
5) Make a backup copy of the file /usr/LH/bin/mythwelcome-config.py
Code:
cp -a -v /usr/LH/bin/mythwelcome-config.py /usr/LH/bin/mythwelcome-config.py.linhes8.2
‘/usr/LH/bin/mythwelcome-config.py’ -> ‘/usr/LH/bin/mythwelcome-config.py.linhes8.2’
6) Modify and execute the file /usr/LH/bin/mythwelcome-config.py
in line 26 put a hashtag "#" and copy and modify this line in 27
Code:
#mythdb.settings.NULL.preSDWUCheckCommand = u'/usr/LH/bin/idle.py -s -d -l -r'
mythdb.settings.NULL.preSDWUCheckCommand = u'/usr/LH/bin/idle-samba.py -s -d -l -r -g'
Execute this file /usr/LH/bin/mythwelcome-config.py to update the Mythtv DB
7) Check in mythtv-setup the new setting of wake up (/usr/LH/bin/idle-samba.py -s -d -l -r -g)
End of modification
Regard Lutz
Optional:
1) If you like to have more information from the idle-samba.py script you can activate the file logging in line 5 and put your own logging.log(logging.INFO) code.
Code:
import logging
logging.basicConfig(
filename="/var/log/mythtv/idle-samba.log",
filemode = "a",
level = logging.DEBUG,
format = "%(asctime)s %(levelname)s: %(message)s",
datefmt = "%d.%m.%Y %H:%M:%S")
logging.log(logging.INFO, "--------------------------------------------------------------")
logging.log(logging.INFO, "Starting idle.py")
You can generate a log file in /var/log/mythtv/ like
Code:
28.01.2015 18:35:03 INFO: --------------------------------------------------------------
28.01.2015 18:35:03 INFO: Starting idle.py
28.01.2015 18:35:03 INFO: User logged in: root
28.01.2015 18:35:03 INFO: System is busy -active samba users-
28.01.2015 18:35:03 INFO: System is busy -active linux user (ssh) or samba users-
28.01.2015 18:35:03 INFO: All checks status:System is busy
2) If you have problems with the message "mythshutdown is locked" you can execute
Code:
mythshutdown -u
mythshutdown -c
OK to shutdown