View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 4 posts ] 
Print view Previous topic   Next topic  
Author Message
Search for:
PostPosted: Wed Jan 28, 2015 5:43 pm 
Offline
Joined: Sun Mar 30, 2014 7:28 am
Posts: 17
Location: Germany, Berlin
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


Last edited by lsteingr01 on Mon Nov 30, 2015 11:45 am, edited 4 times in total.


Top
 Profile  
 
PostPosted: Tue Oct 06, 2015 7:54 am 
Offline
Joined: Sun Mar 30, 2014 7:28 am
Posts: 17
Location: Germany, Berlin
Hi
2015-10-06

This script works with the 8.3 version - the idle.py script have no changes in md5sum.

This are my LinHES versions
Code:
cat /etc/LinHES-release
LinHES R8.3 (Lorne Malvo)

uname -a
Linux sbx1 3.18.14-1-ARCH #1 SMP PREEMPT Wed May 27 17:12:27 UTC 2015 x86_64 GNU/Linux

cat /var/log/pacman.log |grep -i linhes
[2015-01-19 18:04] [PACMAN] upgraded LinHES-system (8.2-3 -> 8.2-5)
[2015-01-19 18:04] [PACMAN] upgraded linhes-theme (8.2-7 -> 8.2-9)
[2015-03-12 14:03] [PACMAN] upgraded LinHES-config (8.2-17 -> 8.3-12)
[2015-03-12 14:03] [PACMAN] upgraded LinHES-system (8.2-5 -> 8.3-9)
[2015-03-12 14:04] [PACMAN] upgraded linhes-theme (8.2-9 -> 8.3-1)
[2015-04-10 14:51] [PACMAN] upgraded LinHES-config (8.3-12 -> 8.3-13)
[2015-04-10 14:51] [PACMAN] upgraded LinHES-system (8.3-9 -> 8.3-11)
[2015-07-10 16:17] [PACMAN] upgraded LinHES-config (8.3-13 -> 8.3-15)
[2015-10-05 15:07] [PACMAN] upgraded LinHES-config (8.3-15 -> 8.3-21)
[2015-10-05 15:07] [PACMAN] upgraded LinHES-system (8.3-11 -> 8.3-14)


After the last update I change only the /usr/LH/bin/mythwelcome-config.py again and start mythwelcome-config.py script
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'


Regards Lutz


Top
 Profile  
 
PostPosted: Tue Oct 06, 2015 12:20 pm 
Offline
Joined: Fri Jul 21, 2006 11:12 pm
Posts: 1194
Location: SC
Good idea.

I just added a -f (or --sambafiles) option to idle.py that checks for Samba files in use and includes it in system busy.

http://cgit.linhes.org/linhes_pkgbuild/ ... c21dea8078


Top
 Profile  
 
PostPosted: Mon Nov 30, 2015 11:39 am 
Offline
Joined: Sun Mar 30, 2014 7:28 am
Posts: 17
Location: Germany, Berlin
2015-11-30

Thanks for updating the idle.py, that 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.
Code:
usage: idle.py [-h] [-d] [-g] [-f] [-l] [-r] [-s] [-t TIME] [-u]

optional arguments:
  -h, --help            show this help message and exit
  -d, --daily           Include daily wake & about to start wake in system
                        busy. (default: daily wake & about to start wake is
                        system idle)
  -g, --logins          Include user logins in system busy. Ignores mythtv
                        (:0) in system busy.
  -f, --sambafiles      Include Samba files in use in system busy.
  -l, --lock            Include mythshutdown lock in system busy. (default:
                        mythshutdown lock is system idle)
  -r, --runningfe       Include running mythfrontends in system busy.
                        (default: running mythfrontends are system idle)
  -s, --silent          Run without printing output. Recommended for use in
                        cron jobs or scripts.
  -t TIME, --time TIME  Minutes of idle time needed to return idle for
                        upcoming recordings and daily wake.
  -u, --usage           Print usage instructions.



If you check for user logins and Samba files in use, use this settings of the /usr/LH/bin/idle.py
Code:
-s -d -l -r -g -f


Change the mythwelcome-config.py

Code:
/usr/LH/bin/mythwelcome-config.py
#mythdb.settings.NULL.preSDWUCheckCommand = u'/usr/LH/bin/idle.py -s -d -l -r'
mythdb.settings.NULL.preSDWUCheckCommand = u'/usr/LH/bin/idle.py -s -d -l -r -g -f'


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 


All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu