From 8a192ea2b2da85868c82728142d70410cd485feb Mon Sep 17 00:00:00 2001 From: Samuel ORTION Date: Sun, 21 Aug 2022 11:50:33 +0200 Subject: [PATCH] logs: Add ttyd on /ttyd endpoint --- INSTALL.md | 27 ++++++++++++++++++- daemon/systemd/templates/birdnet_ttyd.service | 14 ++++++++++ www/nginx.conf.template | 10 +++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 daemon/systemd/templates/birdnet_ttyd.service diff --git a/INSTALL.md b/INSTALL.md index cd75f97..dfee2ff 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -33,7 +33,7 @@ BRANCH=dev ./install.sh ```bash sudo apt-get update -sudo apt-get install python3-dev python3-pip +sudo apt-get install python3-dev python3-pip python3-venv sudo pip3 install --upgrade pip ``` @@ -272,3 +272,28 @@ sudo crontab -e ``` (This updates the certicates every first day of the month, feel free to adapt to your needs.) + +## Setup ttyd to stream audio to webapp + +Change to a dedicated folder, build and install ttyd: + +```bash +cd /opt +sudo wget wget https://github.com/tsl0922/ttyd/releases/download/1.7.1/ttyd.x86_64 # Change to your architecture and get last version +sudo mv ttyd.x86_64 ttyd +sudo chmod +x ttyd +``` + +Set up birdnet_ttyd systemd service to start as a daemon: + +```bash +# Copy service template +sudo cp ./daemon/systemd/templates/birdnet_ttyd.service /etc/systemd/system/birdnet_ttyd.service +# Edit template and adapt placeholders +sudo vim /etc/systemd/system/birdnet_ttyd.service +# Enable and start ttyd service +sudo systemctl daemon-reload +sudo systemctl enable --now birdnet_ttyd.service +``` + +Then go to [https://birdnet.lan/ttyd](https://birdnet.lan/ttyd) and start streaming logs. \ No newline at end of file diff --git a/daemon/systemd/templates/birdnet_ttyd.service b/daemon/systemd/templates/birdnet_ttyd.service new file mode 100644 index 0000000..a8ebb89 --- /dev/null +++ b/daemon/systemd/templates/birdnet_ttyd.service @@ -0,0 +1,14 @@ +[Unit] +Description=BirdNET-stream logs +After=syslog.target +After=network.target + +[Service] +User= +Group= +ExecStart=/opt/ttyd -p 7681 -c birdnet:secret -t disableReconnect=true --readonly journalctl -feu birdnet_\* +Restart=always +Type=simple + +[Install] +WantedBy=multi-user.target diff --git a/www/nginx.conf.template b/www/nginx.conf.template index bf5562a..cb34e56 100644 --- a/www/nginx.conf.template +++ b/www/nginx.conf.template @@ -51,6 +51,16 @@ server { proxy_pass http://localhost:8000/stream; } + location ~ ^/ttyd(.*)$ { + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_pass http://127.0.0.1:7681/$1; + } + access_log /var/log/nginx/birdnet/birdnet-access.log; error_log /var/log/nginx/birdnet/birdnet-error.log error; }