mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Reworked supervisor
This commit is contained in:
parent
55c68b21cd
commit
8793b149f5
@ -7,7 +7,7 @@ author = {
|
|||||||
"email":"maloja@krateng.dev",
|
"email":"maloja@krateng.dev",
|
||||||
"github": "krateng"
|
"github": "krateng"
|
||||||
}
|
}
|
||||||
version = 2,2,4
|
version = 2,3,0
|
||||||
versionstr = ".".join(str(n) for n in version)
|
versionstr = ".".join(str(n) for n in version)
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,28 +5,59 @@ import subprocess
|
|||||||
import time
|
import time
|
||||||
import setproctitle
|
import setproctitle
|
||||||
import signal
|
import signal
|
||||||
|
from datetime import datetime
|
||||||
from doreah.logging import log
|
from doreah.logging import log
|
||||||
from doreah.settings import get_settings
|
from doreah.settings import get_settings
|
||||||
|
|
||||||
|
|
||||||
setproctitle.setproctitle("maloja_supervisor")
|
setproctitle.setproctitle("maloja_supervisor")
|
||||||
|
|
||||||
|
lastrestart = ()
|
||||||
|
|
||||||
while True:
|
def get_pid():
|
||||||
time.sleep(60)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(["pidof","Maloja"])
|
output = subprocess.check_output(["pidof","Maloja"])
|
||||||
pid = int(output)
|
return int(output)
|
||||||
except:
|
except:
|
||||||
log("Maloja is not running, restarting...",module="supervisor")
|
return None
|
||||||
if get_settings("UPDATE_AFTER_CRASH"):
|
|
||||||
log("Updating first...",module="supervisor")
|
def update():
|
||||||
|
log("Updating...",module="supervisor")
|
||||||
try:
|
try:
|
||||||
os.system("pip3 install maloja --upgrade --no-cache-dir")
|
os.system("pip3 install maloja --upgrade --no-cache-dir")
|
||||||
except:
|
except:
|
||||||
log("Could not update.",module="supervisor")
|
log("Could not update.",module="supervisor")
|
||||||
|
|
||||||
|
def start():
|
||||||
try:
|
try:
|
||||||
p = subprocess.Popen(["python3","-m","maloja.server"],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
|
p = subprocess.Popen(["python3","-m","maloja.server"],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
|
||||||
|
|
||||||
except e:
|
except e:
|
||||||
log("Error starting Maloja: " + str(e),module="supervisor")
|
log("Error starting Maloja: " + str(e),module="supervisor")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
time.sleep(60)
|
||||||
|
|
||||||
|
now = datetime.now()
|
||||||
|
today = now.year, now.month, now.day
|
||||||
|
|
||||||
|
pid = get_pid()
|
||||||
|
|
||||||
|
if pid:
|
||||||
|
|
||||||
|
restart = get_settings("DAILY_RESTART")
|
||||||
|
if restart:
|
||||||
|
if today != lastrestart:
|
||||||
|
if now.hour == restart:
|
||||||
|
os.kill(pid,signal.SIGTERM)
|
||||||
|
start()
|
||||||
|
lastrestart = today
|
||||||
|
|
||||||
|
else:
|
||||||
|
log("Maloja is not running, restarting...",module="supervisor")
|
||||||
|
if get_settings("UPDATE_AFTER_CRASH"):
|
||||||
|
update()
|
||||||
|
start()
|
||||||
|
lastrestart = today
|
||||||
|
Loading…
Reference in New Issue
Block a user