fix: set SDL_AUDIODRIVER=pulse and XDG_RUNTIME_DIR for cron/API audio

This commit is contained in:
Markus Graf
2026-06-26 07:42:42 +02:00
parent e118dbc357
commit 0f70e832bf
2 changed files with 13 additions and 1 deletions
+10 -1
View File
@@ -46,18 +46,27 @@ def _default_command() -> str:
"""Return the default shell command to run wecker.py from crontab.""" """Return the default shell command to run wecker.py from crontab."""
project_root = _project_root() project_root = _project_root()
python_exec = sys.executable python_exec = sys.executable
return f"cd {project_root} && {python_exec} wecker.py >> wecker.log 2>&1" runtime_dir = f"/run/user/{os.getuid()}"
return (
f"cd {project_root} && "
f"XDG_RUNTIME_DIR={runtime_dir} SDL_AUDIODRIVER=pulse "
f"{python_exec} wecker.py >> wecker.log 2>&1"
)
def _start_wecker_process() -> subprocess.Popen: def _start_wecker_process() -> subprocess.Popen:
"""Start wecker.py without invoking a shell.""" """Start wecker.py without invoking a shell."""
project_root = _project_root() project_root = _project_root()
env = os.environ.copy()
env.setdefault("SDL_AUDIODRIVER", "pulse")
env.setdefault("XDG_RUNTIME_DIR", f"/run/user/{os.getuid()}")
return subprocess.Popen( return subprocess.Popen(
[sys.executable, str(project_root / "wecker.py")], [sys.executable, str(project_root / "wecker.py")],
cwd=project_root, cwd=project_root,
stdout=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
start_new_session=True, start_new_session=True,
env=env,
) )
+3
View File
@@ -6,6 +6,9 @@ import random
import sys import sys
import os import os
import fcntl import fcntl
# Use PulseAudio/PipeWire audio driver to avoid ALSA device-busy errors.
os.environ.setdefault("SDL_AUDIODRIVER", "pulse")
from logging.handlers import RotatingFileHandler from logging.handlers import RotatingFileHandler
from common import PID_FILE from common import PID_FILE