From 15a423060c76d29c98734212392664be6296be63 Mon Sep 17 00:00:00 2001 From: Krateng Date: Sat, 16 Feb 2019 20:10:12 +0100 Subject: [PATCH] Janky self-restarter --- README.md | 6 +----- restarter.py | 25 +++++++++++++++++++++++++ server.py | 7 +++++++ updater.py | 11 +++++++++-- 4 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 restarter.py diff --git a/README.md b/README.md index 1ca7432..0774bea 100644 --- a/README.md +++ b/README.md @@ -12,10 +12,6 @@ Maloja is self-hosted. You will always be able to access your data, and not have Maloja gets rid of all the extra stuff: social networking, radios, recommendations, etc. It only keeps track of your listening history and lets you analyze it. This focus on its core allows it to potentially implement much better database features. One example: Maloja supports multiple artists per track. This means artists who are often just "featuring" in the track title get a place in your charts, and collaborations between several artists finally get credited to all participants. -### Why not use the established API? - -Compatibility creates overhead effort. I only made this for myself, so I have no need to support lots of music players and scrobblers. Maloja has a significantly smaller API that allows it to be much simpler and implement its additional features. - ### Why Maloja? I like to name my projects after regions in Grisons, Switzerland. Don't waste your time trying to find a connection, I just picked one at random. Do visit Maloja though. It's a great pass to drive. @@ -28,7 +24,7 @@ The software works fairly well and has a few web views, but there is only one sc ## How to install -Installing Maloja is fairly easy on a Linux machine. Don't ask me how to do it on Windows, I have no clue. +Installing Maloja is fairly easy on a Linux machine. Don't ask me how to do it on Windows, I have no clue. Don't ask me to add any lines to make it work on Windows either, the code is already shitty enough. 1) Install the requirements: diff --git a/restarter.py b/restarter.py new file mode 100644 index 0000000..57b28ed --- /dev/null +++ b/restarter.py @@ -0,0 +1,25 @@ +import subprocess +import time + +def startserver(): + time.sleep(5) + print("Starting the Maloja server...") + + p = subprocess.Popen(["python3","server.py"]) + exit("Restarter has done his job and is exiting!") + + +def restart(): + #args = sys.argv[:] + print("Starting the restarter...") + + #args.insert(0, sys.executable) + #print(' '.join(args)) + + p = subprocess.Popen(["python3","restarter.py"]) + #exit("Exiting!") + + + +if __name__ == "__main__": + startserver() diff --git a/server.py b/server.py index 0194430..690032c 100755 --- a/server.py +++ b/server.py @@ -12,6 +12,7 @@ from urllib.error import * import sys import signal import os +import restarter MAIN_PORT = 42010 @@ -67,6 +68,12 @@ def database_post(pth): def shutdown(): graceful_exit() +@webserver.route("/restart") +def restart(): + urllib.request.urlopen("http://[::1]:" + str(DATABASE_PORT) + "/sync") + restarter.restart() + os._exit(42) + def graceful_exit(sig=None,frame=None): urllib.request.urlopen("http://[::1]:" + str(DATABASE_PORT) + "/sync") log("Server shutting down...") diff --git a/updater.py b/updater.py index ebadcad..d273317 100644 --- a/updater.py +++ b/updater.py @@ -4,12 +4,11 @@ import tempfile import zipfile import distutils.dir_util #import os +import sys SOURCE_URL = "https://github.com/krateng/maloja/archive/master.zip" -update() - def update(): print("Updating Maloja...") with urllib.request.urlopen(SOURCE_URL) as response: @@ -27,3 +26,11 @@ def update(): distutils.dir_util.copy_tree("./maloja-master/","./",verbose=2) shutil.rmtree("./maloja-master") print("Done!") + + + + + + +if __name__ == "__main__": + update()