I want to generate pop-ups for certain events in my python script. I am using 'notify-send' for that purpose.
subprocess.Popen(['notify-send', "Authentication", "True/False"])
The above command executes fine on terminal but when I run it from systemd-service it does not generate any pop-up.
When I see logs there are no errors.
Running graphical applications requires the
DISPLAYenvironment variable to be set, which would be set when run it from the CLI, but not when run fromsystemd(unless you explicitly set it).This issue is covered more in Writing a systemd service that depends on XOrg.
I agree with the general advise that
systemdmay not be the best tool for the job. You may be better off using an "auto start" feature of your desktop environment to run your app, which would set the correct things in the environment that you need.