I would like to executea script as root whenever I boot the system. I wrote a shell script:
# cat /home/root/demo_wrap.sh
#!/bin/bash
`/home/root/demo_start.sh` > /dev/null &
that works great when I invoke it from the shell. I wrote the following service file: (Updated according to comments from Edgar Magallon):
# cat /etc/systemd/system/demo_start.service
[Unit]
Description=starts the MH11 demo on EVK
[Service]
Environment="DISPLAY=:0"
Type=forking
XAUTHORITY=/home/root/.Xauthority
ExecStart=/home/root/demo_wrap.sh
[Install]
WantedBy=graphical.target
(I have also tried with DISPLAY:1 s well as XAUTHORITY=/run/user/0 with no success)
but for some reason, # systemctl start demo_start will not invoke the application but report:
[[0;1;31m*[[0m demo_start.service - starts the MH11 demo on EVK
Loaded: loaded (/etc/systemd/system/demo_start.service; enabled; vendor preset: disabled)
Active: [[0;1;31mfailed[[0m (Result: exit-code) since Wed 2022-05-11 18:58:25 UTC; 1min 11s ago
Process: 251 ExecStart=/home/root/demo_wrap.sh (code=exited, status=0/SUCCESS)
Main PID: 252 (code=exited, status=127)
May 11 18:58:18 smarc-rzv2l systemd[1]: Starting starts the MH11 demo on EVK...
May 11 18:58:18 smarc-rzv2l systemd[1]: Started starts the MH11 demo on EVK.
May 11 18:58:25 smarc-rzv2l demo_wrap.sh[254]: error: XDG_RUNTIME_DIR not set in the environment.
May 11 18:58:25 smarc-rzv2l demo_wrap.sh[254]: Connecting to display server failed!: No such file or directory
May 11 18:58:25 smarc-rzv2l demo_wrap.sh[254]: [ERROR] Wayland::init failed
May 11 18:58:25 smarc-rzv2l demo_wrap.sh[252]: /home/root/demo_wrap.sh: line 2: RZ/V2L: No such file or directory
May 11 18:58:25 smarc-rzv2l systemd[1]: [[0;1;39m[[0;1;31m[[0;1;39mdemo_start.service: Main process exited, code=exited, status=127/n/a[[0m
May 11 18:58:25 smarc-rzv2l systemd[1]: [[0;1;38;5;185m[[0;1;39m[[0;1;38;5;185mdemo_start.service: Failed with result 'exit-code'.[[0m
While export XDG_RUNTIME_DIR="/run/user/0" is set in /etc/profile:
export XDG_RUNTIME_DIR=/run/user/$UID
and the weston display manager launches and displays properly on the HDMI screen.
ENVIRONMENT:
This is on an embedded platform with a Yocto built distribution that runs the Weston compositor. When I start a shell window in Weston and type echo $DISPLAY, it does not print anything I expected this to be :0 or :1 (per Edgar Magallon, below). As the terminal window appears prperly on the Weston desktop. This is an embedded reference platform and only has one user root. It is not connected to a network nor will anybody have access to it by connecting any other means of hardware to it. Security is not a concern!
I found the following on the system:
# cat /lib/systemd/system/weston\@.service
[Unit]
Description=Weston Wayland Compositor
RequiresMountsFor=/run
Conflicts=plymouth-quit.service
After=systemd-user-sessions.service plymouth-quit-wait.service
[Service]
User=%i
PAMName=login
EnvironmentFile=-/etc/default/weston
StandardError=journal
PermissionsStartOnly=true
IgnoreSIGPIPE=no
ExecStart=/usr/bin/weston-start -v -e -- $OPTARGS
and my demo should be started after this but it's a bit odd:
# systemctl status weston.service shows me:
[[0;1;32m*[[0m weston.service
Loaded: loaded (/etc/init.d/weston; generated)
Active: [[0;1;32mactive (exited)[[0m since Wed 2022-05-11 18:57:23 UTC; 33min ago
Docs: man:systemd-sysv-generator(8)
Process: 189 ExecStart=/etc/init.d/weston start (code=exited, status=0/SUCCESS)
May 11 18:57:22 smarc-rzv2l systemd[1]: Starting weston.service...
May 11 18:57:23 smarc-rzv2l systemd[1]: Started weston.service.
May 11 18:57:34 smarc-rzv2l weston[196]: Connecting to display server failed!: No such file or directory
May 11 18:57:34 smarc-rzv2l weston[196]: [ERROR] Wayland::init failed
May 11 18:57:35 smarc-rzv2l weston[190]: /etc/profile.d/zz1-demo_wrap.sh: line 2: RZ/V2L: No such file or directory
while Weston is up & running fine.
[Service]section this:Environment="DISPLAY=:0" "XAUTHORITY=/home/youruser/.Xauthoritymaybe/run/user/userIDinstead of/home/youruser/.XauthorityUser=someuserin the [Service] section.DISPLAY=:0toDISPLAY=:1. I see you are using Wayland and unless in my case that uses the value:1instead of:0for the DISPLAY