diff --git a/os/mediamtx/mediamtx.service b/os/mediamtx/mediamtx.service index 845a4a61e..b361a0a8a 100644 --- a/os/mediamtx/mediamtx.service +++ b/os/mediamtx/mediamtx.service @@ -1,10 +1,14 @@ # https://mediamtx.org/docs/usage/start-on-boot#linux [Unit] -After=network.target -Wants=network.target +After=network-online.target +Wants=network-online.target [Service] +# The hostname/IP substitution into /etc/mediamtx.yaml is driven by the +# `runOnInit` hook in the YAML itself (see os/mediamtx/mediamtx.yaml), so it +# also runs when mediamtx is started outside systemd (e.g. `just dev`). +# network-online.target is kept so the wired IP is available when that runs. ExecStart=/usr/local/bin/mediamtx /etc/mediamtx.yaml [Install] diff --git a/os/mediamtx/mediamtx.yaml b/os/mediamtx/mediamtx.yaml index b1714a75b..e5de46de4 100644 --- a/os/mediamtx/mediamtx.yaml +++ b/os/mediamtx/mediamtx.yaml @@ -37,3 +37,8 @@ paths: alwaysAvailable: true alwaysAvailableTracks: - codec: H264 + # Rewrite this file's placeholder hostname/IP (above) with the device's real + # values at startup, so WebRTC ICE candidates resolve regardless of how + # mediamtx was launched (systemd, `just dev`, manual). mediamtx watches the + # config file and hot-reloads after the rewrite. See lib/mediamtx.js. + runOnInit: /usr/bin/node /opt/PlanktoScope/lib/mediamtx.js