I'm desperate. I'm making a camera project with a Raspberry Pi, I'm running Raspbian Buster there, and for the love of God, I cannot make my scripts run after reboot by using systemd. I can start them just fine, but they will be always inactive (dead) after the reboot.
My units are in the /home/pi/.config/systemd/user/ . And they are:
camera-control.service
[Install] WantedBy=multi-user.target [Unit] Description=Camera position controlling server [Service] ExecStart=python3 "${HOME}/scripts/start.camera_control.server.py" And:
camera-stream.service
[Install] WantedBy=multi-user.target [Unit] Description=Camera streaming [Service] ExecStart=bash "${HOME}/scripts/start.stream.sh" The python script basically is running the TCPServer with server.serve_forever(), and bash script is this:
mkdir -p "${HOME}/storage" raspivid --nopreview -ih -hf -vf --width 800 --height 600 --framerate 15 --bitrate 2000000 --profile main --timeout 0 -g 4 -o - | gst-launch-1.0 -v fdsrc do-timestamp=true ! h264parse ! tee name=t \ t. ! queue ! rtph264pay config-interval=1 pt=96 ! udpsink host=dom.zaroda.pl port=8004 \ t. ! queue ! splitmuxsink location="${HOME}/storage/%02d.mkv" max-size-time=30000000000 muxer=matroskamux Both services correctly run with systemctl --user start camera-control. But they never, ever will run after the reboot.
Now I tried A LOT of things. With every change I'm doing systemctl --user daemon-reload and I'm re-enabling them - I'm making sure that they are always enabled.
I tried to add
execbefore theraspivid.I tried to add
this:
After=network-online.target To the Unit section.
and this:
After=network.target and this:
Before=network-online.target And this:
Wants=network-online.target In every configuration I could find on the internet.
I also tried all of this with setting the type of service to: forking and oneshot.
I enabled systemd-networkd service and added to the Unit section things like:
After=systemd-networkd-wait-online.service Requires=systemd-networkd-wait-online.service All of the above in countless configurations. It just won't work. Everytime I will reboot with these two services enabled, I'm getting the same states with systemctl --user status camera-stream and systemctl --user status camera-control :
● camera-stream.service - Camera streaming Loaded: loaded (/home/pi/.config/systemd/user/camera-stream.service; enabled; vendor preset: enabled) Active: inactive (dead) ● camera-control.service - Camera position controlling server Loaded: loaded (/home/pi/.config/systemd/user/camera-control.service; enabled; vendor preset: enabled) Active: inactive (dead) There is nothing in journalctl.
I must be missing something embarrassingly simple. Do you have any suggestions what else I can try to make it work? I feel like I brute forced every configuration of the above mentioned settings imaginable.
Added #1:
One more thing, RPi is being connected to the network by wifi (wlan0). It might or may not be important here.
Added #2:
Services actually work as expected when added to the /etc/systemd/system/ and run "globally". But they refuse to start on boot when run as user, and that's what I'm after.
Output of sudo loginctl show-user pi:
UID=1000 GID=1000 Name=pi Timestamp=Wed 2020-01-01 14:10:16 CET TimestampMonotonic=8249110 RuntimePath=/run/user/1000 [email protected] Slice=user-1000.slice Display=c1 State=active Sessions=c1 IdleHint=no IdleSinceHint=1577884640207702 IdleSinceHintMonotonic=421820778 Linger=yes