Temporary fix for supervisor issues

This commit is contained in:
Krateng 2020-03-08 01:18:31 +01:00
parent 5a08fd78c6
commit 9cf1fb3ed8
6 changed files with 32 additions and 60 deletions

View File

@ -5,7 +5,7 @@ author = {
"email":"maloja@krateng.dev", "email":"maloja@krateng.dev",
"github": "krateng" "github": "krateng"
} }
version = 2,3,2 version = 2,3,3
versionstr = ".".join(str(n) for n in version) versionstr = ".".join(str(n) for n in version)
links = { links = {
"pypi":"malojaserver", "pypi":"malojaserver",
@ -15,7 +15,7 @@ links = {
requires = [ requires = [
"bottle>=0.12.16", "bottle>=0.12.16",
"waitress>=1.3", "waitress>=1.3",
"doreah>=1.5.3", "doreah>=1.5.6",
"nimrodel>=0.6.3", "nimrodel>=0.6.3",
"setproctitle>=1.1.10", "setproctitle>=1.1.10",
"wand>=0.5.4", "wand>=0.5.4",

View File

@ -37,7 +37,7 @@ def setup():
"SPOTIFY_API_ID":"Spotify Client ID", "SPOTIFY_API_ID":"Spotify Client ID",
"SPOTIFY_API_SECRET":"Spotify Client Secret" "SPOTIFY_API_SECRET":"Spotify Client Secret"
} }
SKIP = settings.get_settings("SKIP_SETUP") SKIP = settings.get_settings("SKIP_SETUP")
print("Various external services can be used to display images. If not enough of them are set up, only local images will be used.") print("Various external services can be used to display images. If not enough of them are set up, only local images will be used.")
@ -101,9 +101,9 @@ def getInstanceSupervisor():
def start(): def start():
setup() setup()
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)
sp = subprocess.Popen(["python3","-m","maloja.supervisor"],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL) sp = subprocess.Popen(["python3","-m","maloja.supervisor"],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
print(col["green"]("Maloja started!") + " PID: " + str(p.pid)) print(col["green"]("Maloja started!"))
from doreah import settings from doreah import settings
port = settings.get_settings("WEB_PORT") port = settings.get_settings("WEB_PORT")
@ -126,14 +126,19 @@ def stop():
pid_sv = getInstanceSupervisor() pid_sv = getInstanceSupervisor()
if pid_sv is not None: if pid_sv is not None:
os.kill(pid_sv,signal.SIGTERM) os.kill(pid_sv,signal.SIGTERM)
return True
pid = getInstance() else:
if pid is None:
print("Server is not running") print("Server is not running")
return False return False
else:
os.kill(pid,signal.SIGTERM) # pid = getInstance()
print("Maloja stopped! PID: " + str(pid)) # if pid is None:
# print("Server is not running")
# return False
# else:
# os.kill(pid,signal.SIGTERM)
# print("Maloja stopped! PID: " + str(pid))
return True return True

View File

@ -7,7 +7,7 @@ from .malojatime import register_scrobbletime, time_stamps, ranges
from .urihandler import uri_to_internal, internal_to_uri, compose_querystring from .urihandler import uri_to_internal, internal_to_uri, compose_querystring
from . import compliant_api from . import compliant_api
from .external import proxy_scrobble from .external import proxy_scrobble
from .__init__ import version from .__pkginfo__ import version
from .globalconf import datadir from .globalconf import datadir
# doreah toolkit # doreah toolkit
from doreah.logging import log from doreah.logging import log

View File

@ -20,44 +20,49 @@ def get_pid():
return int(output) return int(output)
except: except:
return None return None
def update(): def update():
log("Updating...",module="supervisor") 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(): 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)
log(p,module="supervisor")
except e: except e:
log("Error starting Maloja: " + str(e),module="supervisor") log("Error starting Maloja: " + str(e),module="supervisor")
while True: while True:
time.sleep(60)
now = datetime.now() now = datetime.now()
today = now.year, now.month, now.day today = now.year, now.month, now.day
pid = get_pid() pid = get_pid()
if pid: if pid:
restart = get_settings("DAILY_RESTART") restart = get_settings("DAILY_RESTART")
if restart: if restart not in [None,False]:
if today != lastrestart: if today != lastrestart:
if now.hour == restart: if now.hour == restart:
log("Daily restart...",module="supervisor")
os.kill(pid,signal.SIGTERM) os.kill(pid,signal.SIGTERM)
start() start()
lastrestart = today lastrestart = today
else: else:
log("Maloja is not running, restarting...",module="supervisor") log("Maloja is not running, starting...",module="supervisor")
if get_settings("UPDATE_AFTER_CRASH"): if get_settings("UPDATE_AFTER_CRASH"):
update() update()
start() start()
lastrestart = today lastrestart = today
time.sleep(60)

View File

@ -15,7 +15,7 @@ from doreah.logging import log
from doreah.regular import yearly, daily from doreah.regular import yearly, daily
from .external import api_request_track, api_request_artist from .external import api_request_track, api_request_artist
from .__init__ import version from .__pkginfo__ import version
from . import globalconf from . import globalconf
from .globalconf import datadir from .globalconf import datadir

View File

@ -1,38 +0,0 @@
import setuptools
import importlib
module = importlib.import_module(setuptools.find_packages()[0])
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="malojaserver",
version=".".join(str(n) for n in module.version),
author=module.author["name"],
author_email=module.author["email"],
description=module.desc,
license="GPLv3",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/" + module.author["github"] + "/" + module.name,
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Operating System :: OS Independent",
],
python_requires=">=3.5",
install_requires=module.requires,
package_data={'': module.resources},
include_package_data=True,
entry_points = {
"console_scripts":[
cmd + " = " + module.name + "." + module.commands[cmd]
for cmd in module.commands
]
}
)
import os
os.system("git tag v" + ".".join(str(n) for n in module.version))