-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain
More file actions
executable file
·98 lines (89 loc) · 2.93 KB
/
main
File metadata and controls
executable file
·98 lines (89 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python3.4
import os
import subprocess as sp
try:
import lir
except:
os.chdir("libraries")
print("Installing Lir Python Module")
sp.getoutput("sudo python3 setup.py install")
os.chdir("../")
import lir
PYTHON = "python3.4"
SERVER = os.getcwd()+"/"+"server"
NOTIF = os.getcwd()+"/"+"notif"
PAIR = os.getcwd()+"/"+"pair"
WIZARD = os.getcwd()+"/"+"wizard"
SETTINGS = None
LIR_FOLDER = lir.FileSystem.home() + "/.lir/"
FIRST_RUN = LIR_FOLDER + ".firstrun"
def attemptStart(cmd,pid = None,python = True):
if pid != None:
if os.path.exists(pid):
with open(pid) as f:
p = f.read().replace("\n","")
if python:
rpid = getPid(PYTHON,cmd)
if rpid != None:
if rpid[0] == p:
#already running
return 1
else:
#different running
return 2
else:
print("Starting: ",cmd)
os.system(cmd+" > /dev/null &")
if python:
npid = getPid(PYTHON,cmd)
with open(pid,'w') as f:
f.write(npid[0])
return 0
else:
#TODO implement later, not yet needed
pass
else:
os.system(cmd+" > /dev/null &")
if python:
npid = getPid(PYTHON,cmd)
with open(pid,'w') as f:
f.write(npid[0])
return 0
else:
os.system(cmd+" > /dev/null &")
def getPid(cmd,options):
out = sp.getoutput("ps -Ao pid,cmd | grep "+options)
out = out.split("\n")
for i in range(0,len(out)):
out[i] = out[i].split(" ")
if len(out[i]) == 4:
out[i] = out[i][1:]
for o in out:
if o[1] == cmd:
return o
return None
def main():
if os.path.exists(FIRST_RUN):
#TODO start notification service
#start server
server = attemptStart(SERVER,LIR_FOLDER+".server.pid")
notif = attemptStart(NOTIF,LIR_FOLDER+".notif.pid")
if server == 0:
print("Server started! PID:",getPid(PYTHON,SERVER)[0])
elif server == 2:
print("Server appears to be running! PID:",getPid(PYTHON,SERVER)[0])
elif server == 1:
print("Server already running! PID:",getPid(PYTHON,SERVER)[0])
if notif == 0:
print("Notif started! PID:",getPid(PYTHON,NOTIF)[0])
elif notif == 2:
print("Notif appears to be running! PID:",getPid(PYTHON,NOTIF)[0])
elif notif == 1:
print("Notif already running! PID:",getPid(PYTHON,NOTIF)[0])
else:
#start wizard
wizard = attemptStart(WIZARD)
print("Wizard:",wizard)
return 0
if __name__ == '__main__':
main()