4

I wanted to send a popup on boot with zenify:

zenity --info --text="`hostname -I`" --title="Rpi Local IP" --display=:0.0 

So here is my service file:

[Unit] Description=Display IP at boot After=networking.service graphical.target Wants=networking.service graphical.target [Service] User=pi Environment=DISPLAY=:0.0 Environment=XAUTHORITY=/home/pi/.Xauthority ExecStart=/bin/bash -c 'zenity --info --text="`hostname -I`" --title="Rpi Local IP" --display=:0.0' [Install] WantedBy=graphical.target 

An error occured everytime:

raspberrypi bash[530]: Invalid MIT-MAGIC-COOKIE-1 keyUnable to init server: Could not connect: Connection refused raspberrypi zenity[530]: cannot open display: :0.0 

If I add like 10 seconds of sleep before starts my service : ExecStartPre=/bin/sleep 10, everything works well.

Where is my mistake ?

Thank you :) !

1 Answer 1

4

Finally managed thanks to this post. Let's say my service file will be "boot_ip.service". First of all, don't create the service as a system service but as a USER service.

Here is the service file ~/.config/systemd/user/boot_ip.service:

[Unit] Description=bootIp PartOf=graphical-session.target [Service] ExecStart=/bin/bash -c 'zenity --info --text="`hostname -I`" --title="Rpi Local IP" --display=:0.0' [Install] WantedBy=xsession.target 

Then create a file called ~/.config/systemd/user/xsession.target:

[Unit] Description=Xsession running BindsTo=graphical-session.target 

This file will indicate that the graphical environment is ready.

Then create a file called .xsessionrc (if I create file .xsession as mentionned in the topic, my graphic environement is broken and I can't even do a simple login so be careful):

systemctl --user import-environment PATH DBUS_SESSION_BUS_ADDRESS systemctl --no-block --user start xsession.target 

This file will be executed once the user is logged in. As you can see, this file will start xsession.target and this will start our service boot_ip.service, problem solved ;) .

2
  • sorry i voted this up -- but now i tried it and it doesn't work (unit script still does not have access to display) Commented Feb 23, 2024 at 21:13
  • sudo systemctl --user import-environment PATH DBUS_SESSION_BUS_ADDRESS Failed to connect to bus: No medium found Commented Feb 21 at 18:34

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.