Improving xscreensaver service


(0 comments)

Because the xscreensaver service needs to run in a graphical session, it should only be started when the graphical procedures and environment are ready. In the scope of systemd's understanding, the target graphical-session-pre.target makes such sense. We will therefore arrange for the xscreensaver service to start after (After=) this target.

In addition, the xscreensaver service needs to be installed as part (PartOf=) of graphical-session.target. The graphical-session.target target will manage the xscreensaver service and will stop the xscreensaver service when the session is terminated.

# /usr/lib/systemd/user/xscreensaver.service
[Unit]
Description=XScreenSaver
ConditionGroup=users
After=graphical-session-pre.target
PartOf=graphical-session.target

[Service]
ExecStart=/usr/bin/xscreensaver -no-splash -no-capture-stderr
Restart=on-failure


The xscreensaver service is now a static service (without the Install section). We define the target xscreensaver.target to start the service using Wants=. The target xscreensaver.target also combines to start the graphical-session.target target with BindsTo=. When the graphic session ends, it also stops the xscreensaver.target target and makes sure the session is terminated clean

# /usr/lib/systemd/user/xscreensaver.target
[Unit]
Description=XScreenSaver
ConditionGroup=users
Wants=xscreensaver.service
BindsTo=graphical-session.target

[Install]
WantedBy=default.target


At startup, the xscreensaver.target target will be pulled in by the default.target target.

Activation will now be done for xscreensaver.target, not xscreensaver.service

systemctl --user enable xscreensaver.target
systemctl --user start xscreensaver.target

Currently unrated

Comments

There are currently no comments

New Comment

required

required (not published)

optional

required


What is 10 - 2?

required