There is an issue starting GStreamer with systemd.
Entering the following command produces an error message and the video doesn't appear.
Help me find a solution.
root@imx8mpevk:~# systemctl start myservice
root@imx8mpevk:~# systemctl status myservice
* myservice.service - test service
Loaded: loaded (/etc/systemd/system/myservice.service; disabled; preset: disabled)
Active: active (running) since Tue 2024-05-14 02:12:25 UTC; 7s ago
Main PID: 834 (myservice.sh)
Tasks: 2 (limit: 5574)
Memory: 5.1M
CGroup: /system.slice/myservice.service
|-834 /bin/bash /home/root/myservice.sh
`-841 sleep 10
May 14 02:12:25 imx8mpevk systemd[1]: Started test service.
May 14 02:12:25 imx8mpevk myservice.sh[834]: gst start!!
May 14 02:12:25 imx8mpevk myservice.sh[835]: Setting pipeline to PAUSED ...
May 14 02:12:25 imx8mpevk myservice.sh[835]: Failed to set pipeline to PAUSED.
May 14 02:12:25 imx8mpevk myservice.sh[835]: Setting pipeline to NULL ...
May 14 02:12:25 imx8mpevk myservice.sh[835]: Freeing pipeline ...
The same shell script works fine when executed in the console, I can see the video.
root@imx8mpevk:~# ./myservice.sh
gst start!!
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
[ 1033.191967] bypass csc
[ 1033.194381] input fmt YUV4
[ 1033.197096] output fmt YUYV
Redistribute latency...
0:00:00.8 / 99:99:99.
Here is my "myservice.service" and "myservice.sh" file.
myservice.service
[Unit]
Description=GStreamer
After=multi-user.target
[Service]
Type=simple
User=root
ExecStart=/home/root/myservice.sh
RemainAfterExit=yes
GuessMainPID=no
myservice.sh
#!/bin/bash
export XDG_RUNTIME_DIR=/run/user/0/
echo gst start!!
gst-launch-1.0 v4l2src device=/dev/video2 ! waylandsink
Please help!!