[systemd-devel] Forward systemd's sleep.target to a systemd user session

Jörg Thalheim joerg at higgsboson.tk
Wed Jul 10 12:04:43 PDT 2013


How I can trigger sleep.target in systemd --user session?

My naive approach was first:

user-sleep at .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 at joerg
    user-sleep at joerg.service - sleep.target of a systemd user session
       Loaded: loaded (/etc/systemd/system/user-sleep at .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 at joerg.service is not needed anymore. Stopping.
    Jun 10 12:30:41 turing-machine systemd[1]: user-sleep at 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 at 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 my jabber client before suspend (I hope this
does not sounds to trivial compared to your serious problems, but you
might come up with other use cases).
This cannot be done in a normal .service file, because it does require a
connection to the current dbus session.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 553 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20130710/3c476cfd/attachment.pgp>


More information about the systemd-devel mailing list