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",
|
||||
"github": "krateng"
|
||||
}
|
||||
version = 2,2,4
|
||||
version = 2,3,0
|
||||
versionstr = ".".join(str(n) for n in version)
|
||||
|
||||
|
||||
|
@ -5,28 +5,59 @@ import subprocess
|
||||
import time
|
||||
import setproctitle
|
||||
import signal
|
||||
from datetime import datetime
|
||||
from doreah.logging import log
|
||||
from doreah.settings import get_settings
|
||||
|
||||
|
||||
setproctitle.setproctitle("maloja_supervisor")
|
||||
|
||||
lastrestart = ()
|
||||
|
||||
while True:
|
||||
time.sleep(60)
|
||||
|
||||
def get_pid():
|
||||
try:
|
||||
output = subprocess.check_output(["pidof","Maloja"])
|
||||
pid = int(output)
|
||||
return int(output)
|
||||
except:
|
||||
log("Maloja is not running, restarting...",module="supervisor")
|
||||
if get_settings("UPDATE_AFTER_CRASH"):
|
||||
log("Updating first...",module="supervisor")
|
||||
return None
|
||||
|
||||
def update():
|
||||
log("Updating...",module="supervisor")
|
||||
try:
|
||||
os.system("pip3 install maloja --upgrade --no-cache-dir")
|
||||
except:
|
||||
log("Could not update.",module="supervisor")
|
||||
|
||||
def start():
|
||||
try:
|
||||
p = subprocess.Popen(["python3","-m","maloja.server"],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
|
||||
|
||||
except e:
|
||||
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