cleanup for new backend

This commit is contained in:
2025-08-15 18:00:28 +02:00
parent f782c28661
commit 16a5768248
6 changed files with 51 additions and 153 deletions

View File

@ -1,13 +1,54 @@
# msv-webcam-frontend
- `zypper install avif-tools`
0) Get [backend running](https://git.mosad.xyz/localhorst/msv-webcam-backend)
1) copy WebApp to `/var/www/html/msv-buehl-moos.de/webcam/`
2) Import following nginx config:
- `mkdir /opt/msv-webcam-frontend/`
- `cd /opt/msv-webcam-frontend/`
- import `msv_webcam_frontend.py`
- `chmod +x /opt/msv-webcam-frontend/msv_webcam_frontend.py`
- `nano /etc/systemd/system/msv-webcam-frontend.service`
- create dst dir `mkdir -p /var/www/html/msv-buehl-moos.de/webcam/data/camera/`
- `systemctl daemon-reload && systemctl enable --now msv-webcam-frontend.service`
```
server
{
listen 80;
listen [::]:80;
server_name msv-buehl-moos.de www.msv-buehl-moos.de;
return 301 https://$host$request_uri;
}
- copy WebApp to `/var/www/html/msv-buehl-moos.de/webcam/`
server
{
server_name msv-buehl-moos.de www.msv-buehl-moos.de;
listen 443 ssl;
listen [::]:443 ssl;
add_header Strict-Transport-Security max-age=31536000;
ssl_certificate /etc/letsencrypt/live/msv-buehl-moos.de/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/msv-buehl-moos.de/privkey.pem;
location /
{
client_max_body_size 10G;
proxy_buffering off;
proxy_pass http://127.0.0.1:27964;
proxy_set_header Accept-Encoding "";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Serve /webcam/data/camera/ from the FTPS current folder
location /webcam/data/camera/
{
alias /home/dockeruser/ftps_server/files/current/;
autoindex on;
}
# Generic /webcam location for the rest of the content
location /webcam
{
root /var/www/html/msv-buehl-moos.de;
index index.html;
}
}
```
3) Test config with `nginx -t`
4) Restart nginx with `systemctl restart nginx.service`

View File

@ -1,16 +0,0 @@
[Unit]
Description=MSV-Webcam-Frontend
After=syslog.target
After=network.target
[Service]
Type=simple
User=wwwrun
Group=wwwrun
Restart=on-failure
RestartSec=5s
WorkingDirectory=/opt/msv-webcam-frontend/
ExecStart=/usr/bin/python3 /opt/msv-webcam-frontend/msv_webcam_frontend.py source_dir=/tmp/msv_webcam_current destination_dir=/var/www/html/msv-buehl-moos.de/webcam/data/camera/ timeout=540 min_size=100000
[Install]
WantedBy=multi-user.target

View File

@ -1,127 +0,0 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" Author: Hendrik Schutter, mail@hendrikschutter.com
"""
import os
import errno
import time
from datetime import datetime
import shutil
import sys
import subprocess
import threading
signal_pipe_path = "/tmp/msv-webcam-signal-pipe"
signal_pipe_msg = "msv-webcam-new-images"
def copy_image(src, destination_dir_path):
#print("src: " + str(src))
#print("dst: " + str(destination_dir_path))
shutil.copyfile(src, destination_dir_path)
def convert_to_avif(input, output):
#print("input: " + str(input))
#print("output: " + str(output))
temp = subprocess.Popen(['avifenc', '--jobs', 'all', input, output], stdout = subprocess.PIPE)
# get the output as a string
#output = str(temp.communicate())
#print(output)
temp = subprocess.Popen(['sync',], stdout = subprocess.PIPE)
def process_new_images(source_dir, destination_dir_path, min_size):
images = os.listdir(source_dir)
for image in images:
if ((os.path.splitext(os.path.basename(os.path.normpath(image)))[1] != ".avif")):
if(os.stat(os.path.join(source_dir, image)).st_size >= min_size):
converted_file_name = (os.path.splitext(os.path.basename(os.path.normpath(image)))[0] + ".avif")
converted_file_path = os.path.join("/tmp/", converted_file_name)
convert_to_avif(os.path.join(source_dir, image), converted_file_path)
copy_image(converted_file_path, os.path.join(destination_dir_path, converted_file_name))
else:
print("Image " + str(image) + " too small.")
def remove_old_image(path):
print("Removing following outdated image: " + str(path))
os.remove(path)
def watchdog(timeout, source_dir, destination_dir_path):
known_images = list()
while True:
images = os.listdir(destination_dir_path)
for image in images:
if ((os.path.splitext(os.path.basename(os.path.normpath(image)))[1] == ".avif")):
current_image = (image, os.stat(os.path.join(destination_dir_path, image)).st_size)
if current_image in known_images:
print("This image is old: " + str(image))
remove_old_image(os.path.join(destination_dir_path, image))
known_images.clear()
images = os.listdir(destination_dir_path)
for image in images:
if ((os.path.splitext(os.path.basename(os.path.normpath(image)))[1] == ".avif")):
current_image = (image, os.stat(os.path.join(destination_dir_path, image)).st_size)
known_images.append(current_image)
time.sleep(timeout)
def main():
print("starting ...")
source_dir = -1
destination_dir_path = -1
timeout = -1
min_size = -1
for argument in sys.argv:
if argument.startswith('destination_dir'):
destination_dir_path = argument.split("=")[1]
if argument.startswith('source_dir'):
source_dir = argument.split("=")[1]
if argument.startswith('timeout'):
timeout = int(argument.split("=")[1])
if argument.startswith('min_size'):
min_size = int(argument.split("=")[1])
if ((source_dir == -1) or (destination_dir_path == -1)):
print("Unable to parse config!")
print("Example usage:")
print(" python msv_webcam_frontend.py source_dir=/tmp/msv_webcam_current destination_dir=www/camera/ timeout=540 min_size=100000")
sys.exit(-1)
watchdog_thread = threading.Thread(target=watchdog, args=((timeout, source_dir, destination_dir_path)))
watchdog_thread.start()
#process_new_images(source_dir, destination_dir_path)
#sys.exit(-1)
while True:
try:
if not os.path.exists(signal_pipe_path):
os.mkfifo(signal_pipe_path)
pipe_fd = os.open(signal_pipe_path, os.O_RDONLY | os.O_NONBLOCK)
with os.fdopen(pipe_fd) as pipe:
while True:
#print("reading pipe")
message = pipe.read()
if message:
#print("Received: " + str(message))
if(message == signal_pipe_msg):
print("received signal about new images")
process_new_images(source_dir, destination_dir_path, min_size)
time.sleep(1)
except Exception as e:
print(e)
watchdog_thread.join()
if __name__ == "__main__":
main()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 244 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 352 KiB

View File

@ -46,7 +46,7 @@
<div class="w3-panel w3-card w3-dark-gray">
<div class="w3-center-align w3-text-black infobox">
<a style="text-decoration: none" href="mailto:pressewart@msv-buehl-moos.de?subject=MSV%20Webcam"><h6>pressewart@msv-buehl-moos.de</h6></a>
<p>Last update: 2023/07/18<p>
<p>Last update: 2025/08/15<p>
<a style="text-decoration: none" href="https://git.mosad.xyz/localhorst/msv-webcam-frontend" target="_blank" rel="noopener noreferrer"><h6>View code in GIT</h6></a>
</div>
</div>