Howto autorun “spreed-webrtc-server” step-by-step
Motivation
As I become struggling by trying to follow instructions like “...you just need to write a simple systemd unit around it...
” I realized that I am still a linux beginner, having some lack on deeper understanding of basic linux behaviour. Therefore I thought it might be helpful to write a step-by-step guide about enabling a systemd unit to autorun the spreed-webrtc-server at startup in the background. This addresses all users that aren’t measurable more experienced in linux than me .
Assumption
- As I am using a current raspbian on raspberrypi for my server, this guide requires systemd to be available and used for init scripts.
- Furthermore I assume you got the spreed server installed and running by downloading it manually from github following the nextcloud guide.
- Struktur AG itself gives some further instructions here.
- @SyS0p3r provides some nice step-by-step guide here in the forum on how to setup the whole debian-related system from the beginning.
- At last I assume that you downloaded and setup the spreed server inside the /opt directory and are finally able to start and use it there:
$ cd /opt
$ wget https://github.com/strukturag/spreed-webrtc/archive/master.zip
$ unzip master.zip
$ cd spreed-webrtc-master
$ ./spreed-webrtc-server
Credits
All credits go to @leon, as he provided the official Spreed WebRTC systemd script here and futher instructions about how to get it running. Thanks for your patience again !
Guide
The following steps will enable a most simple systemd unit for the spreed server without much flourish, to keep the effort as low as possible.
- At first we need to create a system user
spreed:www-data
, that will be used to start the spreed server later by the systemd unit:
$ adduser --quiet --system --ingroup “www-data” --home “/opt/spreed-webrtc-master” --no-create-home --disabled-login “spreed” 2>/dev/null || true
- We will create a log file and chown it to our new user to be able to write it:
$ touch /var/log/spreed.log
$ chown spreed:www-data /var/log/spreed.log
- We will now make the whole spreed server directory executable to the user.
It might be possible to just make a few files executable, but at least the two binaries in server root and /bin, as well as the folders itself are not enough.
$ chmod -R 755 /opt/spreed-webrtc-master
- For whatever reason we need to define the server root directory in its configuration file, otherwise the service will fail:
$ nano /opt/spreed-webrtc-server/server.conf
…
[http]
…
root = /opt/spreed-webrtc-master
…
- Finally we will create the systemd unit itself and enable it to establish the service:
$ nano /etc/systemd/system/spreed.service
[Unit]
Description=Spreed WebRTC server
After=network.target[Service]
Type=simple
Environment=GOMAXPROCS=1
LimitNOFILE=1024
User=spreed
Group=www-data
PermissionsStartOnly=true
ExecStart=/opt/spreed-webrtc-master/bin/spreed-webrtc-server -c /opt/spreed-webrtc-master/server.conf -l /var/log/spreed.log
Restart=on-failure[Install]
WantedBy=multi-user.target//save it
$ systemctl enable spreed.service
$ service spreed start
- (optional) If you use “
logrotate
” you could add an entry for the new “spreed.log
”. Here you’ll find some more information about the possible directives. Adjust them as needed:
$ nano /etc/logrotate.d/spreed
/var/log/spreed.log {
rotate 5
daily
copytruncate
notifempty
missingok
}
- (optional) We could move some variables of the service file into an environment file to be accessible system wide:
$ nano /etc/default/spreed
# Defaults for spreed-webrtc initscripts
WEBRTC_USER=‘spreed’
WEBRTC_GROUP=‘www-data’
WEBRTC_CONF=‘/opt/spreed-webrtc-master/server.conf’
WEBRTC_LOG=‘/var/log/spreed.log’
WEBRTC_GOMAXPROCS=1
WEBRTC_NOFILE=1024//save it
$ nano /etc/systemd/system/spreed.service
[Unit]
Description=Spreed WebRTC server
After=network.target[Service]
Type=simple
EnvironmentFile=/etc/default/spreed
Environment=GOMAXPROCS=${WEBRTC_GOMAXPROCS}
LimitNOFILE=${WEBRTC_NOFILE}
User=${WEBRTC_USER}
Group=${WEBRTC_GROUP}
PermissionsStartOnly=true
ExecStart=/opt/spreed-webrtc-master/bin/spreed-webrtc-server -c ${WEBRTC_CONF} -l ${WEBRTC_LOG}
Restart=on-failure[Install]
WantedBy=multi-user.target
You should be able to check /var/log/spreed.log
after this to see if the server is up as expected. If something failed at an earlier stage of the service startup, you should see further information on /var/log/syslog
.
Congratulations: Your spreedme app should be able to access the server as before from out the nextcloud web interface .
Open questions
- As mentioned above: It might be possible to make just a few files of the server directory executable by everybody. But actually I don’t see any risk by chmod -R 755 the whole directory instead. Correct me if I am wrong.
Further information, questions, advices and criticism is highly appreciated and will be taken into account for tuning this guide.
Best regards,
MichaIng
####Changes:
- Removed unused variables from environment file.
- Added optional logrotate entry.
- Added necessary “
root
” directive to the spreed server configuration file. - Made the environment file an optional step and use
touch
to create empty log file (thanks to @Therion7777) .