2

I am working with raspberry pi os lite on raspberry pi 4.

I wanted to autostart a Qt application.

I created under /etc/systemd/system a .service file named application_one.service

this is what the .service file looks like

[Unit]
Description=Qt application autostart
After=graphical.target
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=pi
WorkingDirectory=/home/pi/a
ExecStart=/home/pi/a/test_v1 -platform linuxfb
[Install]
WantedBy=multi-user.target

after that I enabled this service sudo systemctl enable application_one.service

but it couldn't autostart the apllication after rebooting

when I do sudo systemctl start application_one.service it works fine

these ares the status

sudo systemctl status application_one.service 
くろまる application_one.service - Qt application autostart
 Loaded: loaded (/etc/systemd/system/application_one.service; enabled; vendor 
 Active: inactive (dead)

when booting I have 2 messages before splashscreen

[ 3.005162] systemd[1] : multi-user.target : Job application_one.service/start deleted to break ordering cycle starting with multi-user.target/start

[ 3.005162] systemd[1] : multi-user.target : Job application_one.service/start 
lti-user.target/start

this is what my splashscreen.service looks like :

[Unit]
Description=Splash screen
DefaultDependencies=no
After=local-fs.target
[Service]
ExecStart=/usr/bin/fbi -d /dev/fb0 --noverbose -a /home/pi/image.png
StandardInput=tty
StandardOutput=tty
[Install]
WantedBy=sysinit.target

Can some please explain to me what I am doing wrong

thank you

asked Feb 22, 2021 at 14:49
8
  • You crippled the status output and cut important information. Please add the complete output. What shall the graphical program do when running as service in the background? Why is a GUI needed? Commented Feb 23, 2021 at 9:41
  • I didn't realy understand what you meant can you please clarify. I don't know if you are talking about the framebuffer linuxffb , I am using it because I don't have eglfs available, I used to do an autostart using systemd on the same version of OS and with the same configuration and it worked I don't know why this time it couldn't work. which comptete output? I created a splash screen , so when booting , it shows the splash screen only , the application doesn't start and I got no message or anything Commented Feb 23, 2021 at 10:06
  • Please execute this command: systemctl status application_one.service and add its complete output including CGroup: lines and latest log messages to the question. You use a Qt application that is a GUI library and want to start it after the graphical target. So I assume you are running an application with a graphical user interface. Why do you need a GUI by running /home/pi/a/test_v1 as service continous in the background? Services do not have a user interface. Commented Feb 23, 2021 at 10:15
  • sudo systemctl status application_one.service くろまる application_one.service - Qt application autostart Loaded: loaded (/etc/systemd/system/application_one.service; enabled; vendor Active: inactive (dead) lines 1-3/3 (END) this all what I got Commented Feb 23, 2021 at 10:23
  • The Qt application contains a dashboard actually it contains only some images and some text but I intend to use some gpio pins with the help of the wiringPi library. I just wanted to started after the graphical user interface to make sure it will start and there will be no missing dependencies. the test_v1 is just an exactable of my Qt application that I want to start. is there an other way to autostart it without using a service? Commented Feb 23, 2021 at 10:28

1 Answer 1

2

You created a configuration which is impossible to resolve:

  • application_one.service must start after graphical.target (G before A)
  • graphical.target requires multi-user.target (M before G)
  • multi-user.target wants to start application_one.service (A before M)

One way to break the loop would be swapping the order in which the units load. For instance you have now put After=multi-user.target and WantedBy=graphical.target in your unit file. Your service will start after multi-user.target, but only if graphical.target is about to load. If you want to make sure the GUI is ready when your app is about to load, you may actually want to specify e.g. After=lightdm.target instead of multi-user.

answered Feb 23, 2021 at 14:42
5
  • 1
    Thank you I just verified the order with systemd-analyze critical-chain you are right ! but removing WantedBy=multi-user.target didn't fix the problem because when I tried to enable the service an error showed up The unit files have no installation config (WantedBy=, RequiredBy=, Also=, Alias= settings in the [Install] section, and DefaultInstance= for template units). This means they are not meant to be enabled using systemctl. so I just swapped the two elements : After=multi-user.target WantedBy= graphical.target. Thank you for helping Commented Feb 23, 2021 at 15:16
  • 1
    the strange thing is that I used this configuration like 2 mounths ago interelectronix.com/fr/… and it worked I don't know how Commented Feb 23, 2021 at 15:17
  • 1
    @mina Thanks for reporting the issue, I will fix my answer. Commented Feb 24, 2021 at 10:20
  • 3
    @mina That it works some times and then suddenly no more is respected to the asynchronous (parallel) working of systemd. A very little change in timing to start the services will break the running order if no dependencies set. Commented Feb 24, 2021 at 10:29
  • I think I follow most of your explanation, but one question: Is lightdm.target not included in the Lite distro? I run my systems on the Lite distro, and I have no lightdm.target. I do however, have a graphical.target, but no graphics obviously. Commented Jan 6, 2022 at 9:17

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.