Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 39561
1
#!/usr/bin/python
2
3
import json, os, sys
4
5
SMC = os.environ['SMC']
6
os.chdir(SMC)
7
8
status = {}
9
10
def set(prop, val):
11
status[prop] = val
12
13
def read(prop, filename, strip=False, int_value=False, to_int=False):
14
try:
15
s = open(filename).read()
16
if strip:
17
s = s.strip()
18
if '.port' in prop:
19
try:
20
s = int(s)
21
except TypeError:
22
pass
23
if int_value:
24
s = int(s.split('=')[1])
25
if to_int:
26
s = int(s)
27
status[prop] = s
28
except:
29
status[prop] = False
30
31
def main():
32
for daemon in ['local_hub', 'sage_server', 'console_server']:
33
pidfile = os.path.join(os.path.join(SMC, daemon), '%s.pid'%daemon)
34
if os.path.exists(pidfile):
35
try:
36
pid = int(open(pidfile).read())
37
os.kill(pid, 0)
38
set(daemon+'.pid', pid)
39
except:
40
set(daemon+'.pid', False)
41
else:
42
set(daemon+'.pid', False)
43
44
for name in ['secret_token', 'local_hub/local_hub.port', 'local_hub/raw.port',
45
'console_server/console_server.port', 'sage_server/sage_server.port']:
46
to_int = 'port' in name
47
read(name.split('/')[-1], os.path.join(SMC, name), to_int=to_int)
48
49
print json.dumps(status)
50
51
52
if __name__ == "__main__":
53
main()
54
55