1

I want to set up a service that starts a livestream when booting the rasp. I have been following this tutorial: domoticproject.com/creating-raspberry-pi-service

This is what my .service in /lib/system/system looks like

vi /home/pi/scripts/livestream/livestream.service

[Unit]
Description=Raspberry Livestream
After=network-online.target

[Service]
ExecStart=/bin/bash /home/pi/scripts/livestream/livestream.sh
WorkingDirectory=/home/pi/scripts/livestream/
StandardOutput=inherit
StandardError=inherit
Restart=always
Type=simple
User=pi

[Install]
WantedBy=multi-user.target

starting the livestream with

sudo systemctl start livestream.service

works fine.

I tried to enable the .service to make it start when booting with

sudo systemctl enable livestream.service

but that gives me the following error:

failed to enable unit: File livestream.service: Invalid argument

Any ideas how to solve this?

  • Is vi /home/pi/scripts/livestream/livestream.service really part of your service file? If that's the case you should remove it and try again – Dirk Jun 18 at 15:08
  • that actually did the job! works well, great! – enroot Jun 18 at 19:13
1

vi /home/pi/scripts/livestream/livestream.service is a command to start an editor (vi). It should not be in the service file itself.

Remove it and try to enable the service again.

| improve this answer | |
1

There are some things wrong with your Unit. First you write, your .service is located in /lib/system/system/. If this isn't a typo then this directory isn't managed by systemd. This is /lib/systemd/system but should not be used for your custom service. This directory is reserved for systemd and for services from a distributor. Services there have lower priority and can be overlaid with custom scripts. So you should not use this directory. The best is to let systemd manage your Unit file with its commands. It is not a good idea to fiddle direct with the systemd management directories.

Then your Unit file has some unneeded entries. in general it it always the best to let systemd manage its services itself as most as possible. StandardOutput=inherit and StandardError=inherit is default so you should not use it. Then I do not see why to Restart=always. A proper service do not need to be restarted and to fix a buggy service with it really does not help. It's only a waste of resources to endless try to restart a crashing service. Type=simple is default and not needed.

First revert the configuration you have done. Then check if your script is running from the command line:

rpi ~$ /bin/bash /home/pi/scripts/livestream/livestream.sh

If this works without errors, then you should create your service with:

rpi ~$ sudo systemctl --force --full edit livestream.service

In the empty editor insert these statements, save them and quit the editor:

[Unit]
Description=Raspberry Livestream
After=network-online.target

[Service]
User=pi
WorkingDirectory=/home/pi/scripts/livestream/
ExecStart=/bin/bash /home/pi/scripts/livestream/livestream.sh

[Install]
WantedBy=multi-user.target

Enable, start and manage it as usual, e.g. with sudo systemctl --full edit livestream.service.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.