I would like to replace my Xsession with my custom program (kiosk-like setup), previously I was just setting STARTUP variable in my .xsessionrc file like:
STARTUP='/path/to/my/program'
Now I want to wrap my program as a systemd service to utilize some systemd features like journal logging, configurable automatic restarts, etc. As with previous setup I would prefer to avoid to run 3rd-party session and window managers, but I still have to run something to keep session active, so I've used:
STARTUP='systemd-run --user --scope /path/to/my/program'
However it's still not a convenient systemd unit and finally I've ended up with:
STARTUP='systemd-run --user --scope --unit my-session sleep inf'
and defined a service unit for my program to run:
[Unit]
Description=My service
BindsTo=my-session.scope
Requisite=my-session.scope
After=my-session.scope
[Service]
Type=exec
ExecStart=/path/to/my/program
Restart=always
[Install]
WantedBy=my-session.scope
In general this setup works like a charm however relying on scope name that is generated on the fly seems clunky for me and moreover sometimes it's required to do implicit cleanup on session restart like:
systemctl reset-failed my.service my-session.scope
because systemd complains that my-session.scope already exists.
So, I'm looking for a way to run systemd service synchronously as systemd-run --scope does but same time re-using existing unit file and not generating one on the fly.
P.S.: I've tried following approach but it doesnt work correctly (interrupting systemctl doesnt interrupt the service managed):
systemctl start --wait my-session.target
systemctl start --wait my-session.targetactually worked for me. The only thing I altered, was to remove theRestart=alwaysline from the service file, since I do not want this behavior.