1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Added supervisor to restart on crash, very experimental

This commit is contained in:
Krateng 2019-09-02 01:22:17 +02:00
parent 974574da98
commit fdbeed40f0
2 changed files with 34 additions and 1 deletions

15
maloja
View File

@ -183,12 +183,21 @@ def getInstance():
except:
return None
def getInstanceSupervisor():
try:
output = subprocess.check_output(["pidof","maloja_supervisor"])
pid = int(output)
return pid
except:
return None
def start():
if install():
if gotodir():
setup()
p = subprocess.Popen(["python3","server.py"],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
p = subprocess.Popen(["python3","supervisor.py"],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
print(green("Maloja started!") + " PID: " + str(p.pid))
from doreah import settings
@ -221,8 +230,12 @@ def restart():
return wasrunning
def stop():
pid_sv = getInstanceSupervisor()
if pid_sv is not None:
os.kill(pid,signal.SIGTERM)
pid = getInstance()
if pid == None:
if pid is None:
print("Server is not running")
return False
else:

20
supervisor.py Normal file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env python3
import subprocess
import time
import setproctitle
import signal
setproctitle.setproctitle("maloja_supervisor")
while True:
time.sleep(60)
try:
output = subprocess.check_output(["pidof","Maloja"])
pid = int(output)
except:
print("Maloja not running, restarting...")
p = subprocess.Popen(["python3","server.py"],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)