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:
parent
974574da98
commit
fdbeed40f0
15
maloja
15
maloja
@ -183,12 +183,21 @@ def getInstance():
|
|||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def getInstanceSupervisor():
|
||||||
|
try:
|
||||||
|
output = subprocess.check_output(["pidof","maloja_supervisor"])
|
||||||
|
pid = int(output)
|
||||||
|
return pid
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
if install():
|
if install():
|
||||||
|
|
||||||
if gotodir():
|
if gotodir():
|
||||||
setup()
|
setup()
|
||||||
p = subprocess.Popen(["python3","server.py"],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
|
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))
|
print(green("Maloja started!") + " PID: " + str(p.pid))
|
||||||
|
|
||||||
from doreah import settings
|
from doreah import settings
|
||||||
@ -221,8 +230,12 @@ def restart():
|
|||||||
return wasrunning
|
return wasrunning
|
||||||
|
|
||||||
def stop():
|
def stop():
|
||||||
|
pid_sv = getInstanceSupervisor()
|
||||||
|
if pid_sv is not None:
|
||||||
|
os.kill(pid,signal.SIGTERM)
|
||||||
|
|
||||||
pid = getInstance()
|
pid = getInstance()
|
||||||
if pid == None:
|
if pid is None:
|
||||||
print("Server is not running")
|
print("Server is not running")
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
20
supervisor.py
Normal file
20
supervisor.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user