Commit 039fd24c authored by David Trattnig's avatar David Trattnig
Browse files

Simplistic run targets, excl Liquidsoap. #72

parent 23fd211e
......@@ -26,7 +26,6 @@ import os
import sys
import signal
import logging
import subprocess
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
......@@ -50,11 +49,7 @@ DB = SQLAlchemy(app)
class EngineRunner:
"""
EngineRunner is in charge of
1. Initializing the engine and all dependencies
3. Starting Liquidsoap in a sub-process, if requested
EngineRunner is in charge of starting the engine.
"""
logger = None
config = None
......@@ -71,64 +66,14 @@ class EngineRunner:
self.logger = logging.getLogger("AuraEngine")
def run(self, start_lqs, lqs_debug_flags):
def run(self):
"""
Starts Engine Core.
"""
from src.core.engine import Engine
if start_lqs:
runner.run_lqs(lqs_debug_flags)
else:
self.logger.info(SU.yellow("Please note, Liquidsoap needs to be started manually."))
self.engine = Engine()
def run_lqs(self, lqs_debug_flags):
"""
Starts Liquidsoap.
"""
debug_output = lqs_debug_flags.get("debug_output")
verbose_output = lqs_debug_flags.get("verbose_output")
lqs_path = self.config.get("liquidsoap_path")
lqs_cwd = os.getcwd() + "/" + self.config.get("liquidsoap_working_dir")
lqs_output = ""
lqs_output = self.get_debug_flags(debug_output, verbose_output)
self.lqs = subprocess.Popen([lqs_path, lqs_output, "engine.liq"], \
cwd=lqs_cwd, \
stdout=subprocess.PIPE, \
shell=False)
def get_lqs_cmd(self, debug_output, verbose_output):
"""
Returns a shell command string to start Liquidsoap
"""
lqs_path = self.config.get("liquidsoap_path")
lqs_cwd = os.getcwd() + "/" + self.config.get("liquidsoap_working_dir")
lqs_output = self.get_debug_flags(debug_output, verbose_output)
return "(cd %s && %s %s ./engine.liq)" % (lqs_cwd, lqs_path, lqs_output)
def get_debug_flags(self, debug_output, verbose_output):
"""
Build Liquidsoap debug parameters.
"""
output = ""
if debug_output:
output += "--debug "
if verbose_output:
output += "--verbose "
return output
def recreate_db(self):
"""
Initializes the database and deletes any existing content.
......@@ -137,7 +82,6 @@ class EngineRunner:
AuraDatabaseModel.recreate_db()
def exit_gracefully(self, signum, frame):
"""
Shutdown of the engine. Also terminates the Liquidsoap thread.
......@@ -161,22 +105,12 @@ class EngineRunner:
if __name__ == "__main__":
runner = EngineRunner()
do_start_lqs = True
lqs_cmd = False
signal.signal(signal.SIGINT, runner.exit_gracefully)
signal.signal(signal.SIGTERM, runner.exit_gracefully)
if len(sys.argv) >= 2:
if "--without-lqs" in sys.argv:
do_start_lqs = False
if "--get-lqs-command" in sys.argv:
lqs_cmd = True
if "--recreate-database" in sys.argv:
runner.recreate_db()
sys.exit(0)
if lqs_cmd:
print(runner.get_lqs_cmd(True, True))
else:
runner.run(do_start_lqs, { "debug_output": False, "verbose_output": False })
runner.run()
......@@ -7,10 +7,7 @@ docker="false"
#
# Call with one of these parameters:
#
# - init
# - engine
# - core
# - lqs
# - test
# - recreate-database
......@@ -19,7 +16,7 @@ docker="false"
# - docker:push
#
if [[ $* =~ ^(init|env|engine|core|lqs|test|recreate-database)$ ]]; then
if [[ $* =~ ^(test|recreate-database)$ ]]; then
mode=$1
fi
......@@ -42,33 +39,12 @@ echo "[ Using $(python3 -V) ]"
if [[ $docker == "false" ]]; then
### Initializes the environment & installs dependencies ###
if [[ $mode == "init" ]]; then
mkdir -p logs
pip3 install -r requirements.txt
fi
### Runs Engine Core & Liquidsoap ###
### Runs Engine ###
if [[ $mode == "engine" ]]; then
eval $(opam env)
/usr/bin/env $PYTHON_EXEC run.py
fi
### Runs Engine Core only ###
if [[ $mode == "core" ]]; then
/usr/bin/env $PYTHON_EXEC run.py --without-lqs
fi
### Runs Liquidsoap only ###
if [[ $mode == "lqs" ]]; then
lqs=$(/usr/bin/env $PYTHON_EXEC run.py --get-lqs-command)
eval "$lqs"
fi
### Runs Tests ###
if [[ $mode == "test" ]]; then
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment