2012-10-28, 13:20
Hi, I'm running XBMC on Fedora 17 and I'm looking for a way to disable shutdown timer when there are active samba or ssh connections to the computer. Is there "the way" of doing this?
Thanks
Thanks
(2012-12-01, 21:34)cube Wrote: ... XBMC restarts its shutdown timer if the machine receives WOL packet? How does that work?
#!/usr/bin/python
from __future__ import print_function
import xbmc
import subprocess
# Set of (protocol, local port) tuples.
watched = {
('tcp', 22), # SSH
('tcp', 445), # samba
}
sleep_time = 60 * 1000 # sleep time between checks in miliseconds
def log(msg):
print("service.inhibit_shutdown: {}".format(msg))
def check_services():
""" Check if any of the watched services is running. """
netstat = subprocess.check_output(['/bin/netstat', '--protocol=inet', '-n'], universal_newlines=True)
for line in netstat.split('\n')[2:]:
items = line.split()
if len(items) < 4:
continue
proto = items[0]
port = int(items[3].split(':')[-1])
if (proto, port) in watched:
log("Found {} connection from {} to port {}".format(proto, items[4], port))
return True
log("No connection found.")
return False
while not xbmc.abortRequested:
if check_services():
xbmc.executebuiltin('InhibitIdleShutdown(true)')
else:
xbmc.executebuiltin('InhibitIdleShutdown(false)')
xbmc.sleep(sleep_time)
(2012-12-01, 20:09)cube Wrote: I wrote a service that does this: https://github.com/bluecube/service.inhibit_shutdown ... if anyone finds it usefull.
if len(items) < 4:
continue
local_addr, local_port = items[3].split(':')
remote_addr, remote_port = items[4].split(':')
local_port = int(local_port)
if len(items) < 4:
continue
local_addr, local_port = items[3].split(':')
remote_addr, remote_port = items[4].split(':')
if (remote_addr == "127.0.0.1"):
continue
local_port = int(local_port)