francknos
Posts: 7
Joined: Wed Nov 15, 2017 11:03 am

[SOLVED] Systemd and running program Qt

Wed Nov 15, 2017 11:23 am

Hi everyone,

I'm starting with RPI board.

I want run my GUI program make with Qt call "PM" automaticaly when user is login.

I have make a script like this =>

Code: Select all

#!/bin/bash
mkdir plop
cd plop
date > date.txt

/home/pi/Bureau/PM
I precise that if I write "...Bureau $: ./PM"

My program start correctlly.

Now I try to use systemd to run my program but it doesn't work i think the problem come from systemd.

Here is my service "MyServcie.service" :

Code: Select all

[Unit]
Description:Try to launch Prog Qt
After=graphical.target

[Service]
Type=simple
User=pi
WorkingDirectory=/home/pi/Bureau
ExecStart=/home/pi/Bureau/script

[Install]
WantedBy=graphical.target
The service call the script and the script normally run programm but not .

When I write :
sudo systemctl start MyService.service

The program has not started but I have a folder plop whith date in file so the service has started but not launch my program I don't huserstand why.

Someone can help me thanks.

Franck
Last edited by francknos on Wed Nov 15, 2017 4:52 pm, edited 1 time in total.
:mrgreen: Francknos :mrgreen:

User avatar
RaTTuS
Posts: 10563
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Systemd and running program Qt

Wed Nov 15, 2017 12:34 pm

sudo systemctl status MyService.service
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

francknos
Posts: 7
Joined: Wed Nov 15, 2017 11:03 am

Re: Systemd and running program Qt

Wed Nov 15, 2017 3:11 pm

Here is the output of
sudo systemctl MyService status

Code: Select all

● xfservice.service - Try to launch simple script
   Loaded: loaded (/lib/systemd/system/xfservice.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Wed 2017-11-15 16:04:21 CET; 1s ago
  Process: 5494 ExecStart=/home/pi/Bureau/xfscript & (code=exited, status=0/SUCCESS)
 Main PID: 5494 (code=exited, status=0/SUCCESS)

nov. 15 16:04:20 CM3L systemd[1]: Started Try to launch simple script.
nov. 15 16:04:20 CM3L xfscript[5494]: bonjour ceci est un script lancé automatiquement
nov. 15 16:04:20 CM3L xfscript[5494]: mkdir: impossible de créer le répertoire « ploppppppppppppppppppppppppppppp »: Le fichier existe
nov. 15 16:04:21 CM3L xfscript[5494]: QXcbConnection: Could not connect to display
Here journalctl -xe

Code: Select all

-- L'unité (unit) xfservice.service a terminé son démarrage, avec le résultat done.
nov. 15 16:03:56 CM3L sudo[5450]: pam_unix(sudo:session): session closed for user root
nov. 15 16:03:56 CM3L xfscript[5456]: bonjour ceci est un script lancé automatiquement
nov. 15 16:03:56 CM3L xfscript[5456]: mkdir: impossible de créer le répertoire « ploppppppppppppppppppppppppppppp »: Le fichier existe
nov. 15 16:03:56 CM3L xfscript[5456]: /home/pi/Bureau/xfscript: ligne 10 : .: /home/pi/Bureau/ProbesManager : ne peut exécuter le fichier binaire
nov. 15 16:03:56 CM3L xfscript[5456]: le programme a t il été lancé ?
nov. 15 16:03:56 CM3L sudo[5463]:       pi : TTY=pts/0 ; PWD=/home/pi ; USER=root ; COMMAND=/bin/systemctl status xfservice.service
nov. 15 16:03:56 CM3L sudo[5463]: pam_unix(sudo:session): session opened for user root by (uid=0)
nov. 15 16:03:57 CM3L sudo[5463]: pam_unix(sudo:session): session closed for user root
nov. 15 16:04:17 CM3L sudo[5479]:       pi : TTY=pts/0 ; PWD=/home/pi ; USER=root ; COMMAND=/bin/systemctl status xfservice.service
nov. 15 16:04:17 CM3L sudo[5479]: pam_unix(sudo:session): session opened for user root by (uid=0)
nov. 15 16:04:17 CM3L sudo[5479]: pam_unix(sudo:session): session closed for user root
nov. 15 16:04:20 CM3L sudo[5488]:       pi : TTY=pts/0 ; PWD=/home/pi ; USER=root ; COMMAND=/bin/systemctl start xfservice.service
nov. 15 16:04:20 CM3L sudo[5488]: pam_unix(sudo:session): session opened for user root by (uid=0)
nov. 15 16:04:20 CM3L systemd[1]: Started Try to launch simple script.
-- Subject: L'unité (unit) xfservice.service a terminé son démarrage
-- Defined-By: systemd
-- Support: https://www.debian.org/support
-- 
-- L'unité (unit) xfservice.service a terminé son démarrage, avec le résultat done.
nov. 15 16:04:20 CM3L sudo[5488]: pam_unix(sudo:session): session closed for user root
nov. 15 16:04:20 CM3L xfscript[5494]: bonjour ceci est un script lancé automatiquement
nov. 15 16:04:20 CM3L xfscript[5494]: mkdir: impossible de créer le répertoire « ploppppppppppppppppppppppppppppp »: Le fichier existe
nov. 15 16:04:21 CM3L xfscript[5494]: QXcbConnection: Could not connect to display
nov. 15 16:04:21 CM3L xfscript[5494]: Aborted
nov. 15 16:04:21 CM3L xfscript[5494]: le programme a t il été lancé ?
nov. 15 16:04:22 CM3L sudo[5502]:       pi : TTY=pts/0 ; PWD=/home/pi ; USER=root ; COMMAND=/bin/systemctl status xfservice.service
nov. 15 16:04:22 CM3L sudo[5502]: pam_unix(sudo:session): session opened for user root by (uid=0)
nov. 15 16:04:22 CM3L sudo[5502]: pam_unix(sudo:session): session closed for user root

I have change #!/bin/bash to #!/bin/sh

because /home/pi/Bureau/PM unknow with bash

I think the error is nov. 15 16:04:21 CM3L xfscript[5494]: QXcbConnection: Could not connect to display

But Why I can start my program with execution the script ?
:mrgreen: Francknos :mrgreen:

User avatar
RaTTuS
Posts: 10563
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Systemd and running program Qt

Wed Nov 15, 2017 3:15 pm

QXcbConnection: Could not connect to display
you need some extra environment bits...
export DISPLAY=0.0
maybe ....? does x need to be up before this is able to work ?
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

francknos
Posts: 7
Joined: Wed Nov 15, 2017 11:03 am

Re: Systemd and running program Qt

Wed Nov 15, 2017 3:34 pm

export DISPLAY=0.0
Change nothing.

But my Qt program to run is a simple Application test just a windows.

I don't know why I have error on QXcbConnection: Could not connect to display
:mrgreen: Francknos :mrgreen:

User avatar
RaTTuS
Posts: 10563
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Systemd and running program Qt

Wed Nov 15, 2017 3:47 pm

umm
I'm clutching at straws here but

Code: Select all

nov. 15 16:04:22 CM3L sudo[5502]:       pi : TTY=pts/0 ; PWD=/home/pi ; USER=root ; COMMAND=/bin/systemctl status xfservice.service
seems to suggest user root and not pi

Code: Select all

[Unit]
Description:Try to launch Prog Qt
After=graphical.target
looks good....

I've not used QT so ...
I'll have a think but if anyone else has a clue ? ;)
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6229
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Systemd and running program Qt

Wed Nov 15, 2017 3:58 pm

AIUI, systemd services aren't for starting GUI applications.

Is the idea that this runs automatically when the user logs in, or are you expecting a dedicated X11 session with just this application and nothing else?

francknos
Posts: 7
Joined: Wed Nov 15, 2017 11:03 am

Re: Systemd and running program Qt

Wed Nov 15, 2017 4:13 pm

What I am trying to do is simply launch my program when the desktop is displayed.

like opening the LXTerminal.


What does mean "I'm clutching at straws here but"
:mrgreen: Francknos :mrgreen:

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6229
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Systemd and running program Qt

Wed Nov 15, 2017 4:21 pm

Code: Select all

# Make an autostart directory for the current user:
mkdir -p ~/.config/autostart
# Create a .desktop file which runs your script:
cat > ~/.config/autostart/bureau.desktop << EOF
[Desktop Entry] 
Type=Application
Exec=/home/pi/Bureau/script
EOF
https://wiki.lxde.org/en/Autostart

francknos
Posts: 7
Joined: Wed Nov 15, 2017 11:03 am

Re: Systemd and running program Qt

Wed Nov 15, 2017 4:50 pm

:D :D :D THANKS !!! :mrgreen: :mrgreen: :mrgreen: ShiftPlusOne
It works !!!

So If I have a non GUI application hostapd willl work ?
:mrgreen: Francknos :mrgreen:

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6229
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Systemd and running program Qt

Wed Nov 15, 2017 5:02 pm

francknos wrote:
:D :D :D THANKS !!! :mrgreen: :mrgreen: :mrgreen: ShiftPlusOne
It works !!!
You're welcome.
francknos wrote:So If I have a non GUI application hostapd willl work ?
I think there is some context missing in the question.

User avatar
scruss
Posts: 3256
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Systemd and running program Qt

Wed Nov 15, 2017 7:08 pm

francknos wrote:
Wed Nov 15, 2017 4:13 pm
What does mean "I'm clutching at straws here but"
It means that user RaTTuS was making a guess that they didn't quite believe would work.

Glad you've got this sorted out. Autostart is good.

You can also run user systemd services: create your service file in ~/.config/systemd/user/ then

Code: Select all

systemctl --user enable name_of_my.service
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

Return to “Troubleshooting”