From 05517216570b485c6b643f5a06d127c26dce6a7f Mon Sep 17 00:00:00 2001 From: Jeff Eberl Date: Fri, 29 Nov 2019 22:22:50 -0700 Subject: [PATCH 1/8] Preparing for raspap. --- .../filesystem/home/pi/landingPage/serve.py | 27 ++++++++++++++++-- .../pi/landingPage/templates/landingPage.html | 28 +++++++++++++++++++ src/modules/cncjs/start_chroot_script | 1 + 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/modules/cncjs/filesystem/home/pi/landingPage/serve.py b/src/modules/cncjs/filesystem/home/pi/landingPage/serve.py index 28871b9..faac3ed 100755 --- a/src/modules/cncjs/filesystem/home/pi/landingPage/serve.py +++ b/src/modules/cncjs/filesystem/home/pi/landingPage/serve.py @@ -22,6 +22,23 @@ def getServiceRunning(service): print("{} is unknown".format(service)) return False +def getServiceInstalled(service): + try: + output = subprocess.check_output(['service', service, 'status']) + except subprocess.CalledProcessError as err: + output = err.output + if 'active (running)' in output: + print("{} is running".format(service)) + return True + if 'active (exited)' in output: + print("{} has exited".format(service)) + return True + if 'inactive (dead)' in output: + print("{} is dead".format(service)) + return True + print("{} is unknown".format(service)) + return False + def callService(service, command): print("Running service {} {}".format(service, command)) subprocess.call(['sudo', '/usr/sbin/service', service, command]) @@ -34,17 +51,23 @@ def root(): service = None if 'octoprint' in request.form: service = 'octoprint' - if 'cncjs' in request.form: + elif 'cncjs' in request.form: service = 'cncjs' + elif 'lighttpd' in request.form: + service = 'lighttpd' + else: + return "Not Logical" if 'Start' == request.form[service]: callService(service, 'start') elif 'Stop' == request.form[service]: callService(service, 'stop') elif 'Restart' == request.form[service]: - callService(service, 'Restart') + callService(service, 'restart') return render_template('landingPage.html', octoprint_running=getServiceRunning("octoprint"), + raspap_installed=getServiceInstalled("lighttpd"), + raspap_running=getServiceRunning("lighttpd"), cncjs_running=getServiceRunning("cncjs")) diff --git a/src/modules/cncjs/filesystem/home/pi/landingPage/templates/landingPage.html b/src/modules/cncjs/filesystem/home/pi/landingPage/templates/landingPage.html index f05b929..65006a5 100644 --- a/src/modules/cncjs/filesystem/home/pi/landingPage/templates/landingPage.html +++ b/src/modules/cncjs/filesystem/home/pi/landingPage/templates/landingPage.html @@ -12,6 +12,7 @@

Serve up Octoprint or CNC.js

[about] + [sponsor]
@@ -63,6 +64,33 @@

CNC.js Stopped {% endif %} + {% if raspap_installed %} +
+
+ +
+ +
+ RaspAP +
+
+ {% if raspap_running %} +

RaspAP Running +
+ + +
+

+ {% else %} +

RaspAP Stopped +
+ +
+

+ {% endif %} +
+
+ {% endif %}