Launching Chromium on startup with systemd

And now, the systemd answer.

Since you did ask how to do it with systemd. ☺

This is how the systemd people have been telling people to do this.

You are putting the service unit file in entirely the wrong directory. It should not go in /etc/systemd. It should not even go in /etc/systemd/system. It should go in ~marton/.config/systemd/user.

This is because a graphical program that you want to run under the aegis of your own account is a per-user service not a system service. (You are currently invoking a WWW browser as the superuser. That is a very bad idea. Stop that now!) You could configure it for all users in the /etc/systemd/user directory, but it is probable that not all users on your machine need to start Chromium as a service. So configure it just for your user account, specifically.

As it is a per-user service, you should manipulate it with the --user option to systemctl, sans sudo. For example:

systemctl --user status chrome.service

That goes for enabling and disabling it, too.

As a per-user service unit, it should be WantedBy=default.target, because there is no multi-user.target for per-user services. (Although I suspect it should actually be WantedBy=your-desktop-session.target, which will be something like gnome-session.target depending from what desktop your are using. What the systemd people have been saying is not wondrously clear on this point.)

And one part of the systemd people's bodge to make per-user services look like per-login-session services is the whole graphical-session mechanism, which your service unit must incorporate with the setting:

[Unit]
PartOf=graphical-session.target

What else you have to do depends from how far OpenSuSE has got with the whole graphical-session bodge, which systemd people started pushing in 2016. Ubuntu and Debian provide a whole mess of behind the scenes shell scripting in GUI login session startup and shutdown that bodges both the starting/stopping of graphical-session.target and injecting the DISPLAY environment variable. If your OpenSuSE does not yet have this, you might have to fill in that part.

Further reading

  • Lennart Poettering et al. (2016). systemd.special. systemd manual pages. Freedesktop.org.
  • Martin Pitt (2016-07-25). units: add graphical-session.target user unit. systemd bug #3678.
  • Martin Pitt (2016-09-29). graphical-session.target. systemd.conf. Youtube.
  • Ian Lane (2017-07-30). systemd in GNOME user sessions. GUADEC 2017. Youtube.

In short (additionally to JdeBP):

  1. Never ever use root if not absolutely needed. Least of all for the browser since most of the myriad bugs in them would result in direct root access to the attacker.

  2. Put your systemd files in ~/.config/systemd/user

  3. Enable: E.g. systemctl --user enable firefox

~/.config/systemd/user/firefox.service:

[Unit]
Description=Start Firefox
PartOf=graphical-session.target

[Service]
ExecStart=/usr/bin/firefox
Type=oneshot

[Install]
WantedBy=graphical-session.target

This should start Firefox at boot.


If graphical-session.target is not the right for you (since there is something other managed by the login manager, your display manager or Google knows what) have a look at systemctl --user status *.target what other there might be.


If graphical-session.target is not active after graphical login (you might have an old or stable system), you can manually start it by adding the following to your ~/.xsessionrc:

systemctl --no-block --user start graphical-session.target