1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 """\
21 X2goSessionGuardian class - a guardian thread that controls X2go session threads
22 and their sub-threads (like reverse forwarding tunnels, Paramiko transport threads,
23 etc.).
24
25 """
26 __NAME__ = 'x2goguardian-pylib'
27
28
29 import gevent
30 import threading
31 import copy
32
33
34 from cleanup import x2go_cleanup
35 import x2go_exceptions
36 import log
37
38 _sigterm_received = False
43
45 """\
46 L{X2goSessionGuardian} thread controls X2go session threads and their sub-threads (like
47 reverse forwarding tunnels, Paramiko transport threads, etc.). Its main function is
48 to tidy up once a session gets interrupted (SIGTERM, SIGINT).
49
50 There is one L{X2goSessionGuardian} for each L{X2goClient} instance (thus: for normal
51 setups there should be _one_ L{X2goClient} and _one_ L{X2goSessionGuardian} in use).
52
53 """
54
55 - def __init__(self, client_instance,
56 auto_update_listsessions_cache=False,
57 auto_update_listdesktops_cache=False,
58 auto_update_sessionregistry=False,
59 auto_register_sessions=False,
60 refresh_interval=5,
61 logger=None, loglevel=log.loglevel_DEFAULT):
62 """\
63 @param auto_update_listsessions_cache: let L{X2goSessionGuardian} refresh the session list cache for all L{X2goSession} objects
64 @type auto_update_listsessions_cache: C{bool}
65 @param auto_update_listdesktops_cache: let L{X2goSessionGuardian} refresh desktop lists in the session list cache for all L{X2goSession} objects
66 @type auto_update_listdesktops_cache: C{bool}
67 @param auto_update_sessionregistry: if set to C{True} the session status will be updated in regular intervals
68 @type auto_update_sessionregistry: C{bool}
69 @param auto_register_sessions: register new sessions automatically once they appear in the X2go session (e.g.
70 instantiated by another client that is connected to the same X2go server under same user ID)
71 @type auto_register_sessions: C{bool}
72 @param refresh_interval: refresh cache and session registry every <refresh_interval> seconds
73 @type refresh_interval: C{int}
74 @param logger: you can pass an L{X2goLogger} object to the L{X2goSessionGuardian} constructor
75 @type logger: C{instance}
76 @param loglevel: if no L{X2goLogger} object has been supplied a new one will be
77 constructed with the given loglevel
78 @type loglevel: C{int}
79
80 """
81 if logger is None:
82 self.logger = log.X2goLogger(loglevel=loglevel)
83 else:
84 self.logger = copy.deepcopy(logger)
85 self.logger.tag = __NAME__
86
87 self.client_instance = client_instance
88 self.auto_update_listsessions_cache = auto_update_listsessions_cache
89 self.auto_update_listdesktops_cache = auto_update_listdesktops_cache
90 self.auto_update_sessionregistry = auto_update_sessionregistry
91 self.auto_register_sessions = auto_register_sessions
92 self.refresh_interval = refresh_interval
93
94 threading.Thread.__init__(self, target=self.guardian)
95 self.daemon = True
96 self.start()
97
134
136 """\
137 Stop this L{X2goSessionGuardian} thread.
138
139 """
140 self._keepalive = False
141