From d56f3806fa33f120a742f726da9a90c766c4dd40 Mon Sep 17 00:00:00 2001 From: Samuel ORTION Date: Mon, 15 Aug 2022 14:28:58 +0200 Subject: [PATCH] Add service status and global manager from webapp --- .gitignore | 4 +- config/analyzer.conf.example | 23 ++++++++++ daemon/birdnet_manager.sh | 52 +++++++++++++++++++++++ www/assets/styles/app.css | 40 +++++++++-------- www/src/Controller/ServicesController.php | 2 +- www/templates/base.html.twig | 23 +++++----- www/templates/services/status.html.twig | 9 ++-- 7 files changed, 117 insertions(+), 36 deletions(-) create mode 100644 config/analyzer.conf.example create mode 100755 daemon/birdnet_manager.sh diff --git a/.gitignore b/.gitignore index ecdd97f..0ed91ae 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,6 @@ var/ species_list.txt -push.sh \ No newline at end of file +push.sh + +config/analyzer.conf \ No newline at end of file diff --git a/config/analyzer.conf.example b/config/analyzer.conf.example new file mode 100644 index 0000000..000e110 --- /dev/null +++ b/config/analyzer.conf.example @@ -0,0 +1,23 @@ +# Configuration file for BirdNET Analyzer + +# Coordinates of the recorder +LATITUDE="47.87842" +LONGITUDE="0.21826" +# Species selection list +SPECIES_LIST="./config/species_list.txt" +# Minimal confidence threshold +CONFIDENCE=0.1 +# Recording duration (in seconds) +RECORDING_DURATION=15 +RECORDING_AMPLIFICATION=1.5 +# Chunk folder location +CHUNK_FOLDER="./var/chunks" +# Audio recording device (pulseaudio) +AUDIO_DEVICE="default" +# Virtual env for BirdNET AI with required packages +PYTHON_VENV="./.venv/birdnet-stream" +# Database location +DATABASE="./var/db.sqlite" + +DAEMON_USER="birdnet" +DAEMON_PASSWORD="secret" \ No newline at end of file diff --git a/daemon/birdnet_manager.sh b/daemon/birdnet_manager.sh new file mode 100755 index 0000000..cf30297 --- /dev/null +++ b/daemon/birdnet_manager.sh @@ -0,0 +1,52 @@ +#! /usr/bin/env bash + +set -e +# set -x + +config_filepath="./config/analyzer.conf" + +if [ -f "$config_filepath" ]; then + source "$config_filepath" +else + echo "Config file not found: $config_filepath" + exit 1 +fi + +if [[ -z $DAEMON_USER ]] +then + echo "DAEMON_USER is not set" + exit 1 +fi + +if [[ -z $DAEMON_PASSWORD ]] +then + echo "DAEMON_PASSWORD is not set" + exit 1 +fi + +SERVICES="$(sudo -S <<< $DAEMON_PASSWORD ls /etc/systemd/system/ | grep 'birdnet')" + +DEBUG=${DEBUG:-0} + +debug() { + if [ $DEBUG -eq 1 ]; then + echo "$1" + fi +} + +manage() { + action=$1 + debug "$action birdnet services" + sudo -S <<< $DAEMON_PASSWORD systemctl $action $SERVICES + echo "done" +} + +stop() { + manage stop +} + +start() { + manage start +} + +manage $1 \ No newline at end of file diff --git a/www/assets/styles/app.css b/www/assets/styles/app.css index f0d573e..5e0ed5a 100644 --- a/www/assets/styles/app.css +++ b/www/assets/styles/app.css @@ -8,14 +8,22 @@ position: relative; } -.column { +.container.col { flex-direction: column; } -.row { +.container.row { flex-direction: row; } +.grid { + display: grid; +} + +.grid > * { + padding-left: 0.1em; +} + .behind { position: relative; z-index: -1; @@ -102,40 +110,36 @@ canvas { width: 100%; } -#statuses { - display: flex; - flex-direction: column; -} - #statuses li { list-style: none; - display: flex; - flex-direction: row; - justify-content: space-between; - } -.status .bullet { +#statuses .grid { + display: grid; + grid-template-rows: 1fr 1fr 1fr; + grid-template-columns: 1fr 1fr 1fr; + + gap: 0.1em; +} + +.status.bullet { border-radius: 50%; background-color: #999; width: 1em; height: 1em; display: inline-block; position: relative; - top: 0.15em; - margin-right: 0.5em; - margin-left: 0.5em; + top: 0.4em; } -.status.active .bullet { +.status.active.bullet { background-color: #090; } -.status.inactive .bullet { +.status.inactive.bullet { background-color: #900; } - @media screen and (max-width: 700px) { main { padding: 1em; diff --git a/www/src/Controller/ServicesController.php b/www/src/Controller/ServicesController.php index b404388..dc401bb 100644 --- a/www/src/Controller/ServicesController.php +++ b/www/src/Controller/ServicesController.php @@ -66,7 +66,7 @@ class ServicesController extends AbstractController private function systemd_service_status($service) { - $command = "systemctl is-active ".$service; + $command = "systemctl is-active birdnet_".$service.".service"; $result = shell_exec($command); return $result; } diff --git a/www/templates/base.html.twig b/www/templates/base.html.twig index 2335d34..c292e8b 100644 --- a/www/templates/base.html.twig +++ b/www/templates/base.html.twig @@ -18,18 +18,17 @@ {% block body %} -
- {% include "menu.html.twig" %} -
-
-
-
- {% block content %} -

Welcome to BirdNET-stream !

- {% endblock %} -
- {% include "footer.html.twig" %} -
+ {% include "menu.html.twig" %} +
+ +

BirdNET-stream

+
+
+ {% block content %} +

Welcome to BirdNET-stream !

+ {% endblock %} +
+ {% include "footer.html.twig" %} {% endblock %} diff --git a/www/templates/services/status.html.twig b/www/templates/services/status.html.twig index 46139af..57e0be1 100644 --- a/www/templates/services/status.html.twig +++ b/www/templates/services/status.html.twig @@ -5,11 +5,12 @@ {{ "Services status" | trans }} {% if status is defined and status | length > 0 %} -