Start on boot
Linux
On most Linux distributions (including Ubuntu and Debian, but not OpenWrt), systemd is in charge of managing services and starting them on boot.
Move the server executable and configuration in global folders:
sudo mv mediamtx /usr/local/bin/
sudo mv mediamtx.yml /usr/local/etc/
Create a systemd service:
sudo tee /etc/systemd/system/mediamtx.service >/dev/null << EOF
[Unit]
Wants=network.target
[Service]
ExecStart=/usr/local/bin/mediamtx /usr/local/etc/mediamtx.yml
[Install]
WantedBy=multi-user.target
EOF
If SELinux is enabled (for instance in case of RedHat, Rocky, CentOS++), add correct security context:
semanage fcontext -a -t bin_t /usr/local/bin/mediamtx
restorecon -Fv /usr/local/bin/mediamtx
Enable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable mediamtx
sudo systemctl start mediamtx
OpenWrt
Move the server executable and configuration in global folders:
mv mediamtx /usr/bin/
mkdir -p /usr/etc && mv mediamtx.yml /usr/etc/
Create a procd service:
tee /etc/init.d/mediamtx >/dev/null << EOF
#!/bin/sh /etc/rc.common
USE_PROCD=1
START=95
STOP=01
start_service() {
procd_open_instance
procd_set_param command /usr/bin/mediamtx
procd_set_param stdout 1
procd_set_param stderr 1
procd_close_instance
}
EOF
Enable and start the service:
chmod +x /etc/init.d/mediamtx
/etc/init.d/mediamtx enable
/etc/init.d/mediamtx start
Read the server logs:
logread
Windows
Download the WinSW v2 executable and place it into the same folder of mediamtx.exe
.
In the same folder, create a file named WinSW-x64.xml
with this content:
<service>
<id>mediamtx</id>
<name>mediamtx</name>
<description></description>
<executable>%BASE%/mediamtx.exe</executable>
</service>
Open a terminal, navigate to the folder and run:
WinSW-x64 install
The server is now installed as a system service and will start at boot time.