From c21e289382c8c6fa5e67ce6147a87f8cc2a9a043 Mon Sep 17 00:00:00 2001
From: David Trattnig <david.trattnig@o94.at>
Date: Mon, 27 Apr 2020 16:37:30 +0200
Subject: [PATCH] Improved startup and shutdown.

---
 .vscode/launch.json | 27 ++++++++++++++++++++++-----
 run.sh              | 42 +++++++++++++++++++++++++++---------------
 2 files changed, 49 insertions(+), 20 deletions(-)

diff --git a/.vscode/launch.json b/.vscode/launch.json
index 127cf15..56ec3c0 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -5,14 +5,34 @@
     "version": "0.2.0",
     "configurations": [
         {
-            "name": "Aura Engine - Run",
+            "name": "Start Aura Engine",
             "type": "python",
             "request": "launch",
             "program": "${workspaceFolder}/engine-core.py",
             "console": "integratedTerminal"
         },
         {
-            "name": "Aura Engine API - Run",
+            "name": "Start Engine Core Only",
+            "type": "python",
+            "request": "launch",
+            "program": "${workspaceFolder}/engine-core.py",
+            "args": [
+                "--without-lqs"
+            ],
+            "console": "integratedTerminal"
+        },
+        {
+            "name": "Start Engine LQS Only",
+            "type": "python",
+            "request": "launch",
+            "program": "${workspaceFolder}/engine-core.py",
+            "args": [
+                "--lqs-only"
+            ],
+            "console": "integratedTerminal"
+        },
+        {
+            "name": "Start Engine API",
             "type": "python",
             "request": "launch",
             "stopOnEntry": false,
@@ -23,9 +43,6 @@
             },
             "args": [
                 "run"
-            ],
-            "debugOptions": [
-                "RedirectOutput"
             ]
         },
         {
diff --git a/run.sh b/run.sh
index fb7682f..86ceeb6 100755
--- a/run.sh
+++ b/run.sh
@@ -1,35 +1,47 @@
-#/usr/bin/bash
+#!/bin/bash
 mode="engine"
-debug="--debug"
-#debug="--debug --verbose"
 
 
-if [ -n "$1" ]; then
-	if [[ $1 =~ ^(engine|lqs|api|api-prod)$ ]]; then 
-  		mode=$1 
-	fi
+if [[ $* =~ ^(engine|core|lqs|api-dev|api)$ ]]; then 
+	mode=$1 
 fi
 
 echo "[ Run mode=$mode ]"
 
-if [ $mode == "engine" ]; then
-	/usr/bin/python3.7 aura.py
+
+### Runs Engine Core & Liquidsoap ###
+
+if [[ $mode == "engine" ]]; then
+	/usr/bin/env python3.7 engine-core.py
+fi
+
+### Runs Engine Core only ###
+
+if [[ $mode == "core" ]]; then
+	/usr/bin/env python3.7 engine-core.py --without-lqs
 fi
 
-if [ $mode == "lqs" ]; then
-	(cd modules/liquidsoap/ && liquidsoap $debug ./engine.liq) 
+### Runs Liquidsoap only ###
+
+if [[ $mode == "lqs" ]]; then
+	lqs=$(/usr/bin/env python3.7 engine-core.py --get-lqs-command)
+	eval "$lqs"
 fi
 
-if [ $mode == "api" ]; then
+### Runs the API Server (Development) ###
+
+if [[ $mode == "api-dev" ]]; then
 	echo "Building Web Applications"
 	sh ./script/build-web.sh
 	echo "Starting API Server"
-	/usr/bin/python3.7 api.py
+	/usr/bin/env python3.7 engine-api.py
 fi
 
-if [ $mode == "api-prod" ]; then
+### Runs the API Server (Production) ###
+
+if [[ $mode == "api" ]]; then
 	echo "Building Web Applications"
 	sh ./script/build-web.sh
 	echo "Starting API Server"
-	gunicorn -c configuration/gunicorn.conf.py api:app
+	gunicorn -c configuration/gunicorn.conf.py engine-api:app
 fi
\ No newline at end of file
-- 
GitLab