debug shared_buffer stream
This commit is contained in:
145
service/README.md
Normal file
145
service/README.md
Normal file
@@ -0,0 +1,145 @@
|
||||
# VizionStreamer Systemd Service
|
||||
|
||||
Automatischer Start und Überwachung des VizionStreamer mit systemd.
|
||||
|
||||
## Inhalt
|
||||
|
||||
- `vizionstreamer.service` - Systemd service file
|
||||
- `watchdog.sh` - Watchdog-Script (startet Streamer neu bei Crash)
|
||||
- `install.sh` - Installations-Script
|
||||
- `uninstall.sh` - Deinstallations-Script
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
cd service
|
||||
sudo ./install.sh
|
||||
```
|
||||
|
||||
Das Script:
|
||||
1. Kopiert die Service-Datei nach `/etc/systemd/system/`
|
||||
2. Aktiviert den Service (Start beim Booten)
|
||||
3. Startet den Service sofort
|
||||
|
||||
## Deinstallation
|
||||
|
||||
```bash
|
||||
cd service
|
||||
sudo ./uninstall.sh
|
||||
```
|
||||
|
||||
## Befehle
|
||||
|
||||
### Service verwalten
|
||||
|
||||
```bash
|
||||
# Service starten
|
||||
sudo systemctl start vizionstreamer
|
||||
|
||||
# Service stoppen
|
||||
sudo systemctl stop vizionstreamer
|
||||
|
||||
# Service neu starten
|
||||
sudo systemctl restart vizionstreamer
|
||||
|
||||
# Status anzeigen
|
||||
sudo systemctl status vizionstreamer
|
||||
|
||||
# Autostart deaktivieren
|
||||
sudo systemctl disable vizionstreamer
|
||||
|
||||
# Autostart aktivieren
|
||||
sudo systemctl enable vizionstreamer
|
||||
```
|
||||
|
||||
### Logs anzeigen
|
||||
|
||||
```bash
|
||||
# Live-Logs verfolgen
|
||||
sudo journalctl -u vizionstreamer -f
|
||||
|
||||
# Letzte 100 Zeilen
|
||||
sudo journalctl -u vizionstreamer -n 100
|
||||
|
||||
# Logs seit heute
|
||||
sudo journalctl -u vizionstreamer --since today
|
||||
|
||||
# Alle Logs
|
||||
sudo journalctl -u vizionstreamer --no-pager
|
||||
```
|
||||
|
||||
## Funktionen
|
||||
|
||||
✅ **Automatischer Start** beim Booten
|
||||
✅ **Watchdog** startet Prozess bei Crash neu (max. 10 Versuche)
|
||||
✅ **Systemd Integration** - Logs in journald
|
||||
✅ **Graceful Shutdown** - Sauberes Beenden
|
||||
✅ **Restart-Limit** - Verhindert endlose Restart-Loops
|
||||
|
||||
## Konfiguration
|
||||
|
||||
### Service-Einstellungen anpassen
|
||||
|
||||
Service-Datei bearbeiten:
|
||||
```bash
|
||||
sudo systemctl edit vizionstreamer --full
|
||||
```
|
||||
|
||||
Nach Änderungen:
|
||||
```bash
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl restart vizionstreamer
|
||||
```
|
||||
|
||||
### Watchdog-Intervall ändern
|
||||
|
||||
In `watchdog.sh`:
|
||||
```bash
|
||||
CHECK_INTERVAL=5 # Sekunden (Standard: 5)
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Service startet nicht
|
||||
|
||||
1. Status prüfen:
|
||||
```bash
|
||||
sudo systemctl status vizionstreamer
|
||||
```
|
||||
|
||||
2. Logs prüfen:
|
||||
```bash
|
||||
sudo journalctl -u vizionstreamer -n 50
|
||||
```
|
||||
|
||||
3. Manuell testen:
|
||||
```bash
|
||||
./watchdog.sh
|
||||
```
|
||||
|
||||
### Permissions
|
||||
|
||||
Falls Permission-Probleme:
|
||||
```bash
|
||||
sudo usermod -a -G video maik
|
||||
sudo usermod -a -G audio maik
|
||||
```
|
||||
|
||||
### Service deaktivieren (temporär)
|
||||
|
||||
```bash
|
||||
sudo systemctl stop vizionstreamer
|
||||
sudo systemctl disable vizionstreamer
|
||||
```
|
||||
|
||||
## Systemanforderungen
|
||||
|
||||
- Linux mit systemd
|
||||
- Zugriff auf `/dev/video*` Geräte
|
||||
- User `maik` muss Zugriff auf Kamera haben
|
||||
|
||||
## Support
|
||||
|
||||
Bei Problemen siehe:
|
||||
- `sudo journalctl -u vizionstreamer -f`
|
||||
- `tail -f ../watchdog.log`
|
||||
73
service/install.sh
Executable file
73
service/install.sh
Executable file
@@ -0,0 +1,73 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Installation script for VizionStreamer systemd service
|
||||
|
||||
set -e
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
SERVICE_NAME="vizionstreamer.service"
|
||||
SERVICE_FILE="$(pwd)/vizionstreamer.service"
|
||||
SYSTEMD_DIR="/etc/systemd/system"
|
||||
|
||||
echo -e "${GREEN}=== VizionStreamer Service Installation ===${NC}\n"
|
||||
|
||||
# Check if running as root
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo -e "${RED}Error: This script must be run as root (use sudo)${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if service file exists
|
||||
if [ ! -f "$SERVICE_FILE" ]; then
|
||||
echo -e "${RED}Error: Service file not found: $SERVICE_FILE${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if vizionStreamer executable exists
|
||||
if [ ! -f "/home/maik/CLionProjects/vizionStreamer/build/vizionStreamer" ]; then
|
||||
echo -e "${YELLOW}Warning: vizionStreamer executable not found!${NC}"
|
||||
echo "Please build the project first: cmake --build build"
|
||||
read -p "Continue anyway? (y/N) " -n 1 -r
|
||||
echo
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Stop service if already running
|
||||
if systemctl is-active --quiet $SERVICE_NAME; then
|
||||
echo "Stopping existing service..."
|
||||
systemctl stop $SERVICE_NAME
|
||||
fi
|
||||
|
||||
# Copy service file
|
||||
echo "Installing service file to $SYSTEMD_DIR..."
|
||||
cp "$SERVICE_FILE" "$SYSTEMD_DIR/"
|
||||
|
||||
# Reload systemd
|
||||
echo "Reloading systemd daemon..."
|
||||
systemctl daemon-reload
|
||||
|
||||
# Enable service
|
||||
echo "Enabling service to start on boot..."
|
||||
systemctl enable $SERVICE_NAME
|
||||
|
||||
# Start service
|
||||
echo "Starting service..."
|
||||
systemctl start $SERVICE_NAME
|
||||
|
||||
# Show status
|
||||
echo -e "\n${GREEN}Installation complete!${NC}\n"
|
||||
systemctl status $SERVICE_NAME --no-pager
|
||||
|
||||
echo -e "\n${GREEN}=== Useful Commands ===${NC}"
|
||||
echo " Start: sudo systemctl start $SERVICE_NAME"
|
||||
echo " Stop: sudo systemctl stop $SERVICE_NAME"
|
||||
echo " Restart: sudo systemctl restart $SERVICE_NAME"
|
||||
echo " Status: sudo systemctl status $SERVICE_NAME"
|
||||
echo " Logs: sudo journalctl -u $SERVICE_NAME -f"
|
||||
echo " Disable: sudo systemctl disable $SERVICE_NAME"
|
||||
53
service/uninstall.sh
Executable file
53
service/uninstall.sh
Executable file
@@ -0,0 +1,53 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Uninstallation script for VizionStreamer systemd service
|
||||
|
||||
set -e
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
SERVICE_NAME="vizionstreamer.service"
|
||||
SYSTEMD_DIR="/etc/systemd/system"
|
||||
|
||||
echo -e "${YELLOW}=== VizionStreamer Service Uninstallation ===${NC}\n"
|
||||
|
||||
# Check if running as root
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo -e "${RED}Error: This script must be run as root (use sudo)${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if service exists
|
||||
if [ ! -f "$SYSTEMD_DIR/$SERVICE_NAME" ]; then
|
||||
echo -e "${YELLOW}Service not installed.${NC}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Stop service
|
||||
if systemctl is-active --quiet $SERVICE_NAME; then
|
||||
echo "Stopping service..."
|
||||
systemctl stop $SERVICE_NAME
|
||||
fi
|
||||
|
||||
# Disable service
|
||||
if systemctl is-enabled --quiet $SERVICE_NAME; then
|
||||
echo "Disabling service..."
|
||||
systemctl disable $SERVICE_NAME
|
||||
fi
|
||||
|
||||
# Remove service file
|
||||
echo "Removing service file..."
|
||||
rm -f "$SYSTEMD_DIR/$SERVICE_NAME"
|
||||
|
||||
# Reload systemd
|
||||
echo "Reloading systemd daemon..."
|
||||
systemctl daemon-reload
|
||||
|
||||
# Reset failed state if any
|
||||
systemctl reset-failed $SERVICE_NAME 2>/dev/null || true
|
||||
|
||||
echo -e "\n${GREEN}Uninstallation complete!${NC}"
|
||||
echo "Service '$SERVICE_NAME' has been removed."
|
||||
33
service/vizionstreamer.service
Normal file
33
service/vizionstreamer.service
Normal file
@@ -0,0 +1,33 @@
|
||||
[Unit]
|
||||
Description=VizionStreamer Camera Service with Watchdog
|
||||
After=network.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=maik
|
||||
Group=maik
|
||||
WorkingDirectory=/home/maik/CLionProjects/vizionStreamer
|
||||
ExecStart=/home/maik/CLionProjects/vizionStreamer/service/watchdog.sh
|
||||
Restart=on-failure
|
||||
RestartSec=10s
|
||||
|
||||
# Environment
|
||||
Environment="PATH=/usr/local/bin:/usr/bin:/bin"
|
||||
|
||||
# Logging
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
SyslogIdentifier=vizionstreamer
|
||||
|
||||
# Security settings (optional, kann bei Problemen auskommentiert werden)
|
||||
# NoNewPrivileges=true
|
||||
# PrivateTmp=true
|
||||
|
||||
# Graceful shutdown
|
||||
TimeoutStopSec=30
|
||||
KillMode=mixed
|
||||
KillSignal=SIGTERM
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
119
service/watchdog.sh
Executable file
119
service/watchdog.sh
Executable file
@@ -0,0 +1,119 @@
|
||||
#!/bin/bash
|
||||
|
||||
# VizionStreamer Watchdog Script
|
||||
# Automatically restarts the streamer if it crashes
|
||||
# Usage: ./watchdog.sh
|
||||
|
||||
STREAMER_PATH="./build/vizionStreamer"
|
||||
CHECK_INTERVAL=5 # Seconds between checks
|
||||
LOG_FILE="./watchdog.log"
|
||||
PID_FILE="./vizionStreamer.pid"
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Function to log messages
|
||||
log() {
|
||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
|
||||
}
|
||||
|
||||
# Function to start the streamer
|
||||
start_streamer() {
|
||||
log "${GREEN}Starting VizionStreamer...${NC}"
|
||||
$STREAMER_PATH &
|
||||
STREAMER_PID=$!
|
||||
echo $STREAMER_PID > "$PID_FILE"
|
||||
log "VizionStreamer started with PID: $STREAMER_PID"
|
||||
}
|
||||
|
||||
# Function to check if process is running
|
||||
is_running() {
|
||||
if [ -f "$PID_FILE" ]; then
|
||||
PID=$(cat "$PID_FILE")
|
||||
if ps -p $PID > /dev/null 2>&1; then
|
||||
return 0 # Running
|
||||
fi
|
||||
fi
|
||||
return 1 # Not running
|
||||
}
|
||||
|
||||
# Function to stop the streamer
|
||||
stop_streamer() {
|
||||
if [ -f "$PID_FILE" ]; then
|
||||
PID=$(cat "$PID_FILE")
|
||||
if ps -p $PID > /dev/null 2>&1; then
|
||||
log "${YELLOW}Stopping VizionStreamer (PID: $PID)...${NC}"
|
||||
kill $PID
|
||||
sleep 2
|
||||
# Force kill if still running
|
||||
if ps -p $PID > /dev/null 2>&1; then
|
||||
log "${RED}Force killing VizionStreamer...${NC}"
|
||||
kill -9 $PID
|
||||
fi
|
||||
fi
|
||||
rm -f "$PID_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
# Trap SIGINT and SIGTERM to cleanly shutdown
|
||||
cleanup() {
|
||||
log "${YELLOW}Watchdog shutting down...${NC}"
|
||||
stop_streamer
|
||||
log "${GREEN}Watchdog stopped${NC}"
|
||||
exit 0
|
||||
}
|
||||
|
||||
trap cleanup SIGINT SIGTERM
|
||||
|
||||
# Check if vizionStreamer executable exists
|
||||
if [ ! -f "$STREAMER_PATH" ]; then
|
||||
log "${RED}ERROR: VizionStreamer not found at $STREAMER_PATH${NC}"
|
||||
log "Please build the project first: cmake --build build"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Main watchdog loop
|
||||
log "${GREEN}=== VizionStreamer Watchdog Started ===${NC}"
|
||||
log "Check interval: ${CHECK_INTERVAL} seconds"
|
||||
log "Press Ctrl+C to stop"
|
||||
|
||||
RESTART_COUNT=0
|
||||
|
||||
# Start streamer initially
|
||||
start_streamer
|
||||
sleep 2 # Give it time to start
|
||||
|
||||
while true; do
|
||||
sleep $CHECK_INTERVAL
|
||||
|
||||
if ! is_running; then
|
||||
RESTART_COUNT=$((RESTART_COUNT + 1))
|
||||
log "${RED}VizionStreamer died! Restart count: $RESTART_COUNT${NC}"
|
||||
|
||||
# Optional: limit restart attempts
|
||||
if [ $RESTART_COUNT -gt 10 ]; then
|
||||
log "${RED}ERROR: Too many restarts (10). Giving up.${NC}"
|
||||
log "Check the logs for recurring errors."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Clean up old PID file
|
||||
rm -f "$PID_FILE"
|
||||
|
||||
# Wait a bit before restarting to avoid rapid restart loops
|
||||
sleep 2
|
||||
|
||||
# Restart
|
||||
start_streamer
|
||||
sleep 2
|
||||
else
|
||||
# Still running - reset restart counter on successful check
|
||||
if [ $RESTART_COUNT -gt 0 ]; then
|
||||
RESTART_COUNT=0
|
||||
log "${GREEN}VizionStreamer stable again${NC}"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
Reference in New Issue
Block a user