forked from freeciv/freeciv-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
civlauncher.py
45 lines (41 loc) · 1.77 KB
/
civlauncher.py
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
from threading import Thread
from subprocess import call
from shutil import *
import sys
from time import gmtime, strftime
import time
# The Civlauncher class launches a new instance of a Freeciv-web server in a
# separate thread and restarts the process when the game ends.
class Civlauncher(Thread):
def __init__ (self, gametype, scripttype, new_port, metahostpath, savesdir):
Thread.__init__(self)
self.new_port = new_port;
self.gametype = gametype;
self.scripttype = scripttype;
self.metahostpath = metahostpath;
self.savesdir = savesdir;
self.started_time = strftime("%Y-%m-%d %H:%M:%S", gmtime());
self.num_start = 0;
self.num_error = 0;
def run(self):
while 1:
try:
print("Start freeciv-web on port " + str(self.new_port) +
" and freeciv-proxy on port " + str(1000 + self.new_port) + ".");
retcode = call(["../publite2/init-freeciv-web.sh"
, self.savesdir
, str(self.new_port)
, str(1000 + self.new_port)
, self.metahostpath
, self.gametype
, self.scripttype])
self.num_start += 1;
if retcode > 0:
print("Freeciv-web port " + str(self.new_port) + " was terminated by signal " + str(retcode))
self.num_error += 1;
else:
print("Freeciv-web port " + str(self.new_port) + " returned " + str(retcode))
except OSError as e:
print("Execution failed:", e, file=sys.stderr)
self.num_error += 1;
time.sleep(5)