pi-webrtc

Run as a Service

Start pi-webrtc when the device boots, and restart it if it stops. This page uses systemd.

1. Run PulseAudio as a system service

Skip this step if you use --no-audio. A service has no user session, so PulseAudio must run for the whole system (reference).

  1. Install it:

    sudo apt install pulseaudio
  2. Create /etc/systemd/system/pulseaudio.service:

    [Unit]
    Description=PulseAudio Daemon
    After=rtkit-daemon.service systemd-udevd.service dbus.service
    
    [Service]
    Type=simple
    ExecStart=/usr/bin/pulseaudio --system --disallow-exit --disallow-module-loading
    Restart=always
    RestartSec=10
    
    [Install]
    WantedBy=multi-user.target
  3. Stop clients from starting their own PulseAudio:

    echo 'autospawn = no' | sudo tee -a /etc/pulse/client.conf > /dev/null
  4. Give access, enable the service, and reboot:

    sudo adduser root pulse-access
    sudo systemctl enable pulseaudio.service
    sudo reboot

2. Run pi-webrtc at boot

  1. Create /etc/systemd/system/pi-webrtc.service. Change WorkingDirectory and ExecStart to your own path and options:

    [Unit]
    Description=pi-webrtc camera stream
    After=network-online.target pulseaudio.service
    
    [Service]
    Type=simple
    WorkingDirectory=/path/to
    ExecStart=/path/to/pi-webrtc --config=/path/to/config.yml
    Restart=always
    RestartSec=10
    
    [Install]
    WantedBy=multi-user.target

    A config file keeps ExecStart short. You can also put all the options on the ExecStart line.

  2. Enable and start it:

    sudo systemctl daemon-reload
    sudo systemctl enable pi-webrtc.service
    sudo systemctl start pi-webrtc.service
  3. Check that it runs, and read its log:

    systemctl status pi-webrtc.service
    journalctl -u pi-webrtc.service -f

Restart=always also helps with RTSP input: pi-webrtc exits when the RTSP stream changes its size or codec, and systemd starts it again.

Edit on GitHub

On this page