Add service status and global manager from webapp

This commit is contained in:
Samuel Ortion 2022-08-15 14:28:58 +02:00
parent e44b8542b0
commit d56f3806fa
7 changed files with 117 additions and 36 deletions

4
.gitignore vendored
View File

@ -6,4 +6,6 @@ var/
species_list.txt species_list.txt
push.sh push.sh
config/analyzer.conf

View File

@ -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"

52
daemon/birdnet_manager.sh Executable file
View File

@ -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

View File

@ -8,14 +8,22 @@
position: relative; position: relative;
} }
.column { .container.col {
flex-direction: column; flex-direction: column;
} }
.row { .container.row {
flex-direction: row; flex-direction: row;
} }
.grid {
display: grid;
}
.grid > * {
padding-left: 0.1em;
}
.behind { .behind {
position: relative; position: relative;
z-index: -1; z-index: -1;
@ -102,40 +110,36 @@ canvas {
width: 100%; width: 100%;
} }
#statuses {
display: flex;
flex-direction: column;
}
#statuses li { #statuses li {
list-style: none; 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%; border-radius: 50%;
background-color: #999; background-color: #999;
width: 1em; width: 1em;
height: 1em; height: 1em;
display: inline-block; display: inline-block;
position: relative; position: relative;
top: 0.15em; top: 0.4em;
margin-right: 0.5em;
margin-left: 0.5em;
} }
.status.active .bullet { .status.active.bullet {
background-color: #090; background-color: #090;
} }
.status.inactive .bullet { .status.inactive.bullet {
background-color: #900; background-color: #900;
} }
@media screen and (max-width: 700px) { @media screen and (max-width: 700px) {
main { main {
padding: 1em; padding: 1em;

View File

@ -66,7 +66,7 @@ class ServicesController extends AbstractController
private function systemd_service_status($service) private function systemd_service_status($service)
{ {
$command = "systemctl is-active ".$service; $command = "systemctl is-active birdnet_".$service.".service";
$result = shell_exec($command); $result = shell_exec($command);
return $result; return $result;
} }

View File

@ -18,18 +18,17 @@
</head> </head>
<body> <body>
{% block body %} {% block body %}
<div class="above"> {% include "menu.html.twig" %}
{% include "menu.html.twig" %} <header>
</div> <img class="logo" src="/media/logo.svg" alt="BirdNET logo">
<div class="behind"> <h1>BirdNET-stream</h1>
<header></header> </header>
<main> <main>
{% block content %} {% block content %}
<p>Welcome to BirdNET-stream !</p> <p>Welcome to BirdNET-stream !</p>
{% endblock %} {% endblock %}
</main> </main>
{% include "footer.html.twig" %} {% include "footer.html.twig" %}
</div>
{% endblock %} {% endblock %}
</body> </body>
</html> </html>

View File

@ -5,11 +5,12 @@
{{ "Services status" | trans }} {{ "Services status" | trans }}
</h2> </h2>
{% if status is defined and status | length > 0 %} {% if status is defined and status | length > 0 %}
<ul id="statuses"> <ul id="statuses" class="container column">
{% for service in status %} {% for service in status %}
<li> <li class="grid">
<span class="name">{{ service["name"] }}</span> <div class="col status bullet {{ service["status"] }}"></div>
<span class="status"><span class="bullet {{ service["status"] }}"></span>{{ service["status"] }}</span> <div class="col name">{{ service["name"] }}</div>
<div class="col status">{{ service["status"] }}</div>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>