-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstart
executable file
·76 lines (68 loc) · 1.97 KB
/
start
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
#!/usr/bin/env python2
# -*- coding: ISO-8859-1 -*-
#
# Copyright (C) 2003 by Frank Lübeck and Max Neunhöffer
#
'''Start the OKUSON server and show logfile line until service is started.'''
import sys,os,time
homedir = os.path.abspath(sys.path[0])
os.environ["OKUSONHOME"] = homedir
# We perform a few sanity checks and give appropriate messages:
logdir = os.path.join(homedir,'log')
if not(os.path.exists(logdir)):
try:
os.mkdir(logdir)
except:
print "Error: "+logdir+' directory cannot be created.'
print 'Aborting.'
sys.exit(0)
if not(os.path.isdir(logdir)):
print 'Error: '+logdir+' must be a directory.'
print 'Aborting.'
sys.exit(0)
logfile = os.path.join(homedir,'log/server.log')
if not(os.path.exists(logfile)) or not(os.path.isfile(logfile)):
try:
file(logfile,"w").close()
except:
print 'Error: '+logfile+' must be writable.'
print 'Aborting.'
sys.exit(0)
pid = os.fork()
if pid == 0:
time.sleep(0.1) # Let the parent get hold of the log file
server = os.path.join(homedir,"server/Server.py")
os.execl(server,server)
try:
f = file(logfile,"r")
except:
print "Cannot find log file log/server.log."
sys.exit(0)
f.seek(0,2) # seek to end of file
p = f.tell()
ok = 0
while 1:
f.seek(0,2)
np = f.tell()
if np > p:
f.seek(p)
s = f.readlines()
p = f.tell()
for l in s:
if l[:29] == 'Error: Cannot start service!':
sys.stdout.write(l)
sys.exit(1)
elif ok:
sys.exit(0)
elif l[-27:] == 'Ready to start service ...\n':
sys.stdout.write(l)
ok = 1
s = s+f.readlines()
if l == s[-1]:
sys.exit(0)
elif l == 'Aborting.\n':
sys.stdout.write(l)
sys.exit(0)
else:
sys.stdout.write(l)
time.sleep(0.5)