You are not logged in.
My naive approach was the following:
user-sleep@.service
[Unit]
Description=sleep.target of a systemd user session
Before=sleep.target
StopWhenUnneeded=yes
[Service]
Type=oneshot
User=%I
RemainAfterExit=yes
ExecStart=/usr/bin/systemctl --user start sleep.target
ExecStop=/usr/bin/systemctl --user stop sleep.target
[Install]
WantedBy=sleep.target
sleep.target
[Unit]
Description=Sleep Timer Target
StopWhenUnneeded=yes
Unfortunately I got the following error:
$ systemctl status user-sleep@joerg
user-sleep@joerg.service - sleep.target of a systemd user session
Loaded: loaded (/etc/systemd/system/user-sleep@.service; enabled)
Active: failed (Result: exit-code) since Mo 2013-06-10 12:30:41 CEST; 43min ago
Process: 10503 ExecStart=/usr/bin/systemctl --user start sleep.target (code=exited, status=1/FAILURE)
Jun 10 12:30:41 turing-machine systemd[1]: Service user-sleep@joerg.service is not needed anymore. Stopping.
Jun 10 12:30:41 turing-machine systemd[1]: user-sleep@joerg.service: main process exited, code=exited, status=1/FAILURE
Jun 10 12:30:41 turing-machine systemd[1]: Failed to start sleep.target of a systemd user session.
Jun 10 12:30:41 turing-machine systemd[1]: Unit user-sleep@joerg.service entered failed state.
Can I use "systemctl --user" only at a login shell and not in a systemd unit? Because using "systemd --user" from tty works great.
My use case is to logout gajim before suspend. This cannot be done in a normal .service file, because it does require a connection to the current dbus session.
Offline
Thank you for your idea! I''ve successfully configured this.
systemctl communicates with systemd via D-Bus. For --user, it's the session D-Bus, so you need to set that right. Try to add this to your user-sleep@.service and see if it works for you. Also you'll need to use user ID instead of user name.
Environment=DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/%I/bus
]
Offline