From 6e021de1c77287dfaa5c560e37c35a007540b8b2 Mon Sep 17 00:00:00 2001 From: pstruebi Date: Tue, 19 Aug 2025 15:13:55 +0200 Subject: [PATCH] add a service for the auracast script --- src/service/auracast-script.service | 14 ++++ src/service/status_auracast_services.sh | 84 +++++++++++++++++++ src/service/stop_auracast_script.sh | 15 ++++ src/service/update_and_run_auracast_script.sh | 23 +++++ 4 files changed, 136 insertions(+) create mode 100644 src/service/auracast-script.service create mode 100755 src/service/status_auracast_services.sh create mode 100644 src/service/stop_auracast_script.sh create mode 100644 src/service/update_and_run_auracast_script.sh diff --git a/src/service/auracast-script.service b/src/service/auracast-script.service new file mode 100644 index 0000000..b979a62 --- /dev/null +++ b/src/service/auracast-script.service @@ -0,0 +1,14 @@ +[Unit] +Description=Auracast Multicast Script +After=network.target + +[Service] +Type=simple +WorkingDirectory=/home/caster/bumble-auracast +ExecStart=/home/caster/.local/bin/poetry run python src/auracast/multicast_script.py +Restart=on-failure +Environment=PYTHONUNBUFFERED=1 +Environment=LOG_LEVEL=INFO + +[Install] +WantedBy=default.target diff --git a/src/service/status_auracast_services.sh b/src/service/status_auracast_services.sh new file mode 100755 index 0000000..c7f6b17 --- /dev/null +++ b/src/service/status_auracast_services.sh @@ -0,0 +1,84 @@ +#!/bin/bash +set -euo pipefail + +# Print status of relevant services and warn if mutually exclusive ones are running. +# Utilities (network audio): +# - ptp_aes67.service (system) +# - pipewire-aes67.service (user) +# App services (mutually exclusive groups): +# - auracast-script.service (user) +# - auracast-server.service (prefer user; also check system) +# - auracast-frontend.service (system) + +print_status() { + local scope="$1" # "system" or "user" + local unit="$2" + local act="unknown" + local ena="unknown" + if [[ "$scope" == "user" ]]; then + act=$(systemctl --user is-active "$unit" 2>/dev/null || true) + ena=$(systemctl --user is-enabled "$unit" 2>/dev/null || true) + else + act=$(systemctl is-active "$unit" 2>/dev/null || true) + ena=$(systemctl is-enabled "$unit" 2>/dev/null || true) + fi + act="${act:-unknown}" + ena="${ena:-unknown}" + printf " - %-24s [%s] active=%-10s enabled=%s\n" "$unit" "$scope" "$act" "$ena" +} + +is_active() { + local scope="$1" unit="$2" + if [[ "$scope" == "user" ]]; then + systemctl --user is-active "$unit" &>/dev/null && echo yes || echo no + else + systemctl is-active "$unit" &>/dev/null && echo yes || echo no + fi +} + +hr() { printf '\n%s\n' "----------------------------------------"; } + +printf "AURACAST SERVICE STATUS\n" +hr + +printf "Utilities (required for network audio)\n" +print_status system ptp_aes67.service +print_status user pipewire-aes67.service + +PTP_ACTIVE=$(is_active system ptp_aes67.service) +PW_ACTIVE=$(is_active user pipewire-aes67.service) + +if [[ "$PTP_ACTIVE" == "yes" && "$PW_ACTIVE" == "yes" ]]; then + echo " ✓ Utilities ready for AES67/network audio" +else + echo " ! Utilities not fully active (AES67/network audio may not work)" +fi + +hr +printf "Application services (mutually exclusive)\n" +print_status user auracast-script.service +print_status user auracast-server.service +print_status system auracast-server.service +print_status system auracast-frontend.service + +SCRIPT_ACTIVE=$(is_active user auracast-script.service) +SERVER_USER_ACTIVE=$(is_active user auracast-server.service) +SERVER_SYS_ACTIVE=$(is_active system auracast-server.service) +FRONT_ACTIVE=$(is_active system auracast-frontend.service) + +# Consider server active if either user or system instance is active +if [[ "$SERVER_USER_ACTIVE" == "yes" || "$SERVER_SYS_ACTIVE" == "yes" ]]; then + SERVER_ACTIVE=yes +else + SERVER_ACTIVE=no +fi + +if [[ "$SCRIPT_ACTIVE" == "yes" && ( "$SERVER_ACTIVE" == "yes" || "$FRONT_ACTIVE" == "yes" ) ]]; then + echo " ! WARNING: 'auracast-script' and 'server/frontend' are running together (mutually exclusive)." +fi + +hr +printf "Hints\n" +echo " - Follow logs (user): journalctl --user -u auracast-script.service -f" +echo " - Follow logs (server): journalctl --user -u auracast-server.service -f || journalctl -u auracast-server.service -f" +echo " - Frontend logs: journalctl -u auracast-frontend.service -f" diff --git a/src/service/stop_auracast_script.sh b/src/service/stop_auracast_script.sh new file mode 100644 index 0000000..a95ab26 --- /dev/null +++ b/src/service/stop_auracast_script.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -e + +# This script stops and disables the auracast-script user service + +# Stop service +systemctl --user stop auracast-script.service || true + +# Disable service from starting on login +systemctl --user disable auracast-script.service || true + +echo "\n--- auracast-script.service status (user) ---" +systemctl --user status auracast-script.service --no-pager || true + +echo "auracast-script service stopped, disabled, and status printed successfully." diff --git a/src/service/update_and_run_auracast_script.sh b/src/service/update_and_run_auracast_script.sh new file mode 100644 index 0000000..83bfbbc --- /dev/null +++ b/src/service/update_and_run_auracast_script.sh @@ -0,0 +1,23 @@ +#!/bin/bash +set -e + +# This script installs, enables, and restarts the auracast-script user service +# No sudo is required as it is a user service + +# Copy user service file for auracast-script +mkdir -p /home/caster/.config/systemd/user +cp /home/caster/bumble-auracast/src/service/auracast-script.service /home/caster/.config/systemd/user/auracast-script.service + +# Reload systemd to recognize new/updated services +systemctl --user daemon-reload + +# Enable service to start on user login +systemctl --user enable auracast-script.service + +# Restart service +systemctl --user restart auracast-script.service + +echo "\n--- auracast-script.service status (user) ---" +systemctl --user status auracast-script.service --no-pager + +echo "auracast-script service updated, enabled, restarted, and status printed successfully."