1#!/usr/bin/python 2 3# Simple script that will restard ded server if it hung 4# You do not need that script on Windows - we have ded server installed as system service there 5 6import time 7import os 8import sys 9import signal 10 11import subprocess 12 13if sys.platform == "win32": 14 import ctypes 15 16 17olxPath = "openlierox.exe" # Modify here the path to OLX binary 18TimeToSleep=60 # OLX and ded server will write something in logs once per 40 seconds 19 20def startProcess(): 21 print "Starting " + olxPath 22 if sys.platform == "win32": 23 proc = subprocess.Popen( [olxPath, olxPath, "-dedicated"] ) 24 else: 25 proc = os.spawnvp( os.P_NOWAIT, "sh", ["sh", "-c", "./" + olxPath + " -dedicated > stdout.txt"] ) 26 return proc 27 28def killProcess(proc): 29 if sys.platform == "win32": 30 # Doesn't work anyway 31 ctypes.windll.kernel32.TerminateProcess( proc.pid, 1 ) 32 else: 33 os.kill( proc, signal.SIGKILL ) 34 35proc = startProcess() 36uptime = time.time() 37 38def signalHandler(signum, frame): 39 print "Signal caught - exiting" 40 print "Killing process, uptime was %f hours" % ( ( time.time() - uptime ) / 3600 ) 41 killProcess(proc) 42 sys.exit() 43 44signal.signal(signal.SIGTERM, signalHandler) 45signal.signal(signal.SIGABRT, signalHandler) 46signal.signal(signal.SIGINT, signalHandler) 47if sys.platform != "win32": 48 signal.signal(signal.SIGQUIT, signalHandler) 49 50time.sleep(3) 51 52fileSize1 = os.stat("stdout.txt").st_size 53fileSize2 = os.stat("dedicated_control.log").st_size 54time.sleep(TimeToSleep) 55 56while True: 57 58 #print "stdout.txt size %i was %i, dedicated_control.log size %i was %i" % \ 59 # ( os.stat("stdout.txt").st_size, fileSize1, os.stat("dedicated_control.log").st_size, fileSize2 ) 60 if fileSize1 == os.stat("stdout.txt").st_size or fileSize2 == os.stat("dedicated_control.log").st_size: 61 print "Killing process, uptime was %f hours" % ( ( time.time() - uptime ) / 3600 ) 62 killProcess(proc) 63 proc = startProcess() 64 uptime = time.time() 65 66 fileSize1 = os.stat("stdout.txt").st_size 67 fileSize2 = os.stat("dedicated_control.log").st_size 68 69 time.sleep(TimeToSleep) 70 71