Re: [systemd-devel] Fwd: best way to handle service restarts after hibernate/suspend?

2013-08-08 Thread 孙冰
I use this:

[Unit]
Description=Wicd sleep hook
Before=sleep.target
StopWhenUnneeded=yes

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=-/usr/share/wicd/daemon/suspend.py
ExecStop=-/usr/share/wicd/daemon/autoconnect.py

[Install]
WantedBy=sleep.target
-

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Fwd: best way to handle service restarts after hibernate/suspend?

2013-08-08 Thread Mathijs Kwik
孙冰 subi.the.dream.wal...@gmail.com writes:

 I use this:
 
 [Unit]
 Description=Wicd sleep hook
 Before=sleep.target
 StopWhenUnneeded=yes

 [Service]
 Type=oneshot
 RemainAfterExit=yes
 ExecStart=-/usr/share/wicd/daemon/suspend.py
 ExecStop=-/usr/share/wicd/daemon/autoconnect.py

 [Install]
 WantedBy=sleep.target
 -

Clever :)

It turns out I always misinterpreted the documentation for
StopWhenUnneeded. I never read past the first sentence and assumed this
option was only going to stop services when it felt like it.

But this is a very nice solution, still stateful (remainafterexit) but
by focusing on the sleep-state instead of the before-sleep and
after-sleep it nicely works around cyclic/conflicting dependencies.

Thanks!

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Fwd: best way to handle service restarts after hibernate/suspend?

2013-08-08 Thread killermoehre
Am 08.08.2013 08:12, schrieb 孙冰:
 I use this:
 
 [Unit]
 Description=Wicd sleep hook
 Before=sleep.target
 StopWhenUnneeded=yes
 
 [Service]
 Type=oneshot
 RemainAfterExit=yes
 ExecStart=-/usr/share/wicd/daemon/suspend.py
 ExecStop=-/usr/share/wicd/daemon/autoconnect.py
 
 [Install]
 WantedBy=sleep.target
 -

Thank you very much for this idea. I think it can be expressed in a more
generic way:


[Unit]
Description=%I sleep hook
Before=sleep.target
StopWhenUnneeded=yes

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=-/usr/bin/systemctl stop %I
ExecStop=-/usr/bin/systemctl start %I

[Install]
WantedBy=sleep.target
-

It would be invoked from sleep-hook@.service.
What do you think?



signature.asc
Description: OpenPGP digital signature
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Fwd: best way to handle service restarts after hibernate/suspend?

2013-08-08 Thread 孙冰
Hi,

Yep. I have the exact same sleep@.service and it works.

BTW, sleep.target is pulled in by both suspend.target and
hibernate.target. There are some use cases that a hook should be only
invoked by suspend.target (or hibernate.target). For instance, I have a
hook used with the tuxoniceui:


[Unit]
Description=tuxoniceui hibernate hook
Before=hibernate.target
StopWhenUnneeded=yes

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStartPre=/bin/bash -c echo `fgconsole`  %t/tuxoniceui
ExecStart=/bin/chvt 63
ExecStop=-/bin/bash -c chvt ` %t/tuxoniceui`
ExecStopPost=-/bin/rm -rf %t/tuxoniceui

[Install]
WantedBy=hibernate.target



Obviously I don't want it to be called for suspend.target. The problem
is, by default, suspend.target/hibernate.target is not a
StopWhenUnneeded service. I have to overwrite it in
/etc/systemd/system/hibernate.target.d. It's completely OK for me to do
this. What I wonder is, what is the reason by they are not
StopWhenUnneeded services?

Uh, seems overly off-topic... 

Regards.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Fwd: best way to handle service restarts after hibernate/suspend?

2013-08-07 Thread Tom Gundersen
On Wed, Aug 7, 2013 at 10:12 AM, Mathijs Kwik math...@bluescreen303.nl wrote:
 I have a few things that need to get run after waking up my laptop
 (things like hdparm to set device power options/spindown time).
 I created oneshot, remainafterexit services for those and made them
 wanted by multi-user.target.This works fine for the first boot.

Are you sure you want RemainAfterExit? Without it you should be able
to set WantedBy=sleep.target and After=sleep.target.

 As I consider these services dead after a suspend/hibernate, I added
 Conflicts=sleep.target, so now systemd is aware that these services
 are no longer active after a wakeup.

 Now I would like to somehow have these services restart on wakeup.
 I can add these services to some new target(wakeup.target), but I
 don't know how to proceed from there. I thought of making
 wakeup.target WantedBy suspend.target, After suspend.target, but since
 suspend.target pulls in sleep.target (which conflicts with these
 services) that will fail. More so, after wakeup.target is started the
 first time, it will never go down itself, so the second wakeup won't
 do anything. The same is true for multi-user.target, once that is
 reached/activated on first boot, it never deactivates until shutdown.

 How should a situation like this be handled?
 Ideally, I don't want to use:
 - /usr/lib/systemd/system-sleep  (considered hacky)
 - a service/script that runs systemctl start ...  (secret
 dependency, hidden from systemd)

 Thanks,
 Mathijs
 ___
 systemd-devel mailing list
 systemd-devel@lists.freedesktop.org
 http://lists.freedesktop.org/mailman/listinfo/systemd-devel
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel