How do I open thunderbird automatically as a systemd service? (" Error: no DISPLAY environment variable " failure)

I’m trying to set up a computer for a bit of a weird situation with some elderly relatives, and the key criteria is I need Thunderbird to open on boot, and STAY open, even if they accidentally close it, or it crashes for some other reason.

I’m trying to set this up as systemd service, as this seems to be the generally standardized method for auto-starting stuff, it’s easy (ish), I’m familiar(ish) with it and it has provisions for auto restart and so on if it crashes.

Problem I’m having is it seems to failing be asking for some sort of environment/display variable. Config file (placed in /etc/systemd/system ) is at the end.

[test@fedora ~]$ systemctl daemon-reload
[test@fedora ~]$ systemctl start thunderbird
[test@fedora ~]$ systemctl status thunderbird
× thunderbird.service - Thunderbird
     Loaded: loaded (/etc/systemd/system/thunderbird.service; disabled; preset: disabled)
     Active: failed (Result: exit-code) since Sat 2023-01-07 15:30:35 AEDT; 3s ago
   Duration: 119ms
    Process: 11667 ExecStart=/usr/bin/thunderbird (code=exited, status=1/FAILURE)
   Main PID: 11667 (code=exited, status=1/FAILURE)
        CPU: 93ms

Jan 07 15:30:35 fedora systemd[1]: Started thunderbird.service - Thunderbird.
Jan 07 15:30:35 fedora thunderbird[11667]: Error: no DISPLAY environment variable specified
Jan 07 15:30:35 fedora systemd[1]: thunderbird.service: Main process exited, code=exited, status=1/FAILURE
Jan 07 15:30:35 fedora systemd[1]: thunderbird.service: Failed with result 'exit-code'.

I’ve read through a few docs and done a google sweep and it’s all the usual level of irrelevant or incomprehensible. I cant find any info specifically relevant to systemd and just need to get this working before we have more problems

Can anyone advise the correct way to configure this?


PS yes I know I can just use a .desktop file to autostart it, but that wont auto restart and as I said, this a weird situation and half the problem is the user getting confused and closing things. I’m not looking for suggestions on how to create different problems going a different way, I’m after suggestions of solving this specific problem - this will do what I need if I fix this issue, and I’d like to know how to used systemd for this purpose going forward.





The service file should to info /etc/systemd/user/thunderbird.service
and the WantedBy should be

Programs which interact with users need to be running in a user session, thus the service file must be put in the user directory.


Sorry, this doesn’t seem to have worked, now i just get:

[test@fedora ~]$ systemctl  start thunderbird
Failed to start thunderbird.service: Unit thunderbird.service not found.

When you start user units, you add the “–user” option.

systemctl --user start thunderbird

You may be going in the wrong direction.
Is thunderbird not an app with its own desktop icon to launch?

The related .desktop file (/usr/share/applications/mozilla-thunderbird.desktop) could be copied into ~/.config/autostart/ for the user and it would automatically start when that user logged in. I know it would not automatically restart that way, but if it crashes and needs to restart it is super easy to place it on the dash and teach the user to use the ‘super’ key to access the dash and launch it again.

I also just added an app that I wanted to auto start at boot time (system wide) and when I added the service file it was not allowed to start until I used restorecon to properly set the selinux context for that file.

1 Like

I very clearly stated that this was not a suitable solution from the outset, and explained why. Either you didn’t bother to read rully, or chose to outright ignore it - why, I don’t know.

Either way, it doesn’t give you ground to declare my approach the ‘wrong’ direction (which is demonstrably isn’t - with the right flags, it worked perfectly). Moreover, Instructing someone to change the circumstance of their problem to validate your ideas of a solution is not a helpful contribution.

This fixed it perfectly, thankyou. adding the --user flag to all commands makes it work exaclty as normal, I understand now that running it as root, it doesnt have access to the desktop/display environment by default, hence the error.

Through another forum I was also advised to make the following modifications to the .service file, to enable auto restart (with a trigger to stop after 5 attempts in the case of a bug). I also switched to the Thunderbird flatpak for unrelated reasons.


ExecStart=flatpak run org.mozilla.Thunderbird


Interestingly, or seem both to work.

In any case I now have exactly what I sought - a systemd process that starts the Thunderbird on login automatically, and keeps it running if closed. Thanks for the help


By the way, to enable a user service for all users, specify “–global” instead of “–user”. You may need to do this with sudo.