source: lliurex-shutdowner/trunk/fuentes/lliurex-shutdowner-common.install/usr/sbin/shutdown-lliurex @ 5538

Last change on this file since 5538 was 5538, checked in by hectorgh, 3 years ago

adding thin-client support

  • Property svn:executable set to *
File size: 1.5 KB
RevLine 
[5407]1#!/usr/bin/env python
2
3import subprocess
4import os
[5426]5import time
[5407]6
[5426]7wait_time=1
[5537]8p=subprocess.Popen(["who"],shell=True,stdout=subprocess.PIPE).communicate()[0]
[5426]9ret=os.system("lliurex-version -t server")
[5537]10is_thin=os.system("lliurex-version -x thin")
[5407]11
[5538]12thinclient_cron_file="/etc/cron.d/lliurex-shutdowner-thinclients"
13
[5407]14if ret==0:
[5537]15        if is_thin!=0:
16                wait_time=2
[5407]17
[5426]18t=time.localtime()
19shutdown_date="%s:%s"%(t.tm_hour,t.tm_min+wait_time)
20
[5537]21displays=set()
[5426]22
[5407]23for item in p.strip("\n").split("\n"):
24        x=item.split(" ")
25        user=x[0]
[5537]26        if "(" not in x[-1] or ")" not in x[-1] or ":" not in x[-1] or "." not in x[-1]:
[5407]27                continue
28        display=x[-1].lstrip("(").rstrip(")")
[5538]29       
30        # If thinclient_cron_file exists, this is being called from the server to show shutdown dialog
31        # to thin clients
32        # if this is being called from the server and thincron_file doesn't exist, then it means server
33        # will handle every dialog call
34       
35        if is_thin==0 and os.path.exists(thincron_file):
36                if len(display.split(":")[0].split("."))<4:
37                        continue
38       
[5537]39        if display not in displays:
40                displays.add(display)
41        else:
42                continue
[5444]43        cmd="su -c 'DISPLAY=%s /usr/sbin/shutdown-lliurex-dialog %s' %s &"%(display,wait_time,user)
[5407]44        os.system(cmd)
45
46
[5537]47if is_thin!=0:
48        os.system("/sbin/shutdown -h +%s"%wait_time)
49else:
[5538]50        if is_thin==0:
51                if not os.path.exists(thincron_file):
52                        # this means this is being called inside thin client
53                        time.sleep(60*wait_time)
54                        os.system("n4d-client -r -m shutdown -c ShutdownerClient")
55                else:
56                        #this means this is being called from the server
57                        #Shutdown will be handled inside thin client
58                        pass
[5407]59
Note: See TracBrowser for help on using the repository browser.