grandkodiak
Posts: 12
Joined: Sat Sep 15, 2018 2:45 pm

systemd .service file to run script at startup on delay issue

Thu Sep 16, 2021 10:03 pm

I have a script that runs a vlc output from my camera, problem is that when the power goes out or it reboots, i have to log back in and start the script manually.

i found some guides online that said to create a .service file to call the script but i cant seem to get it to function.

1.created a systemd service file

/etc/systemd/system/camera.service

2.inserted this text into camera.service :


[Unit]
Description=Run camera script at startup

[Service]
Type=oneshot
ExecStart=/home/pi/camera.sh
TimeoutStartSec=0



3.reload services:

systemctl daemon-reload

4.rebooted

Boots fine but vlc not running.

what am I doing wrong?

bls
Posts: 1762
Joined: Mon Oct 22, 2018 11:25 pm
Location: Seattle, WA

Re: systemd .service file to run script at startup on delay issue

Thu Sep 16, 2021 10:24 pm

grandkodiak wrote:
Thu Sep 16, 2021 10:03 pm
I have a script that runs a vlc output from my camera, problem is that when the power goes out or it reboots, i have to log back in and start the script manually.

i found some guides online that said to create a .service file to call the script but i cant seem to get it to function.

1.created a systemd service file

/etc/systemd/system/camera.service

2.inserted this text into camera.service :


[Unit]
Description=Run camera script at startup

[Service]
Type=oneshot
ExecStart=/home/pi/camera.sh
TimeoutStartSec=0



3.reload services:

systemctl daemon-reload

4.rebooted

Boots fine but vlc not running.

what am I doing wrong?
You didn't mention doing an sudo systemctl enable camera. If you don't do that, systemd won't know to start the service.
Also, I'm pretty sure that every .service file needs an Install section at the end of the file with, for example:

Code: Select all

[Install]
WantedBy=multi-user.target
See man systemd.service for a treasure trove of details, and ALWAYS check the system log with journalctl when fussing around with systemd stuff.
Pi tools:
Quickly and easily build customized-just-for-you SSDs/SD Cards: https://github.com/gitbls/sdm
Easily run and manage your network's DHCP/DNS servers on a Pi: https://github.com/gitbls/ndm
Easy and secure strongSwan VPN installer/manager: https://github.com/gitbls/pistrong
Lightweight Virtual VNC Config: https://github.com/gitbls/RPiVNCHowTo

grandkodiak
Posts: 12
Joined: Sat Sep 15, 2018 2:45 pm

Re: systemd .service file to run script at startup on delay issue

Fri Sep 17, 2021 5:25 pm

that was it! added the install line in camera.service, ran the enable, rebooted, and shes off to the races!

thank you!

on a side note, i dont see it as a process anywhere but it is indeed up and running. if i wanted to shut it down, would disabling the service and refreshing again the method?




ps. i also had to make vlc executable as root for anyone w the same problems with:

sudo sed -i 's/geteuid/getppip/' /usr/bin/vlc

guessing because its starting before the standard loggin where i normally am when starting the script manually

bls
Posts: 1762
Joined: Mon Oct 22, 2018 11:25 pm
Location: Seattle, WA

Re: systemd .service file to run script at startup on delay issue

Fri Sep 17, 2021 6:48 pm

grandkodiak wrote:
Fri Sep 17, 2021 5:25 pm
that was it! added the install line in camera.service, ran the enable, rebooted, and shes off to the races!

thank you!

on a side note, i dont see it as a process anywhere but it is indeed up and running. if i wanted to shut it down, would disabling the service and refreshing again the method?




ps. i also had to make vlc executable as root for anyone w the same problems with:

sudo sed -i 's/geteuid/getppip/' /usr/bin/vlc

guessing because its starting before the standard loggin where i normally am when starting the script manually
To stop the service:

Code: Select all

sudo systemctl stop camera
To disable the service so that it doesn't start automatically on boot:

Code: Select all

sudo systemctl disable camera
If you disable the service you can still use sudo systemctl start camera to start it after the system has booted.

I can't comment on the making vlc executable as root, as I don't have it installed anywhere to have a look at it, but Mr. Google/DuckDuckGo/Bing should be helpful.
Pi tools:
Quickly and easily build customized-just-for-you SSDs/SD Cards: https://github.com/gitbls/sdm
Easily run and manage your network's DHCP/DNS servers on a Pi: https://github.com/gitbls/ndm
Easy and secure strongSwan VPN installer/manager: https://github.com/gitbls/pistrong
Lightweight Virtual VNC Config: https://github.com/gitbls/RPiVNCHowTo

Return to “Beginners”