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

2013-08-09 Thread Lennart Poettering
On Wed, 07.08.13 10:12, Mathijs Kwik (math...@bluescreen303.nl) wrote:

> Hi all,
> 
> 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.
> 
> 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)

Well, doing hdparm fiddling after suspend is a hack in itself, hence
/usr/lib/systemd/system-sleep/ is precisely the right hacky choice to
implement something like this. It's simple, synchronous and the intended
place to put hacks like this.

Lennart

-- 
Lennart Poettering - Red Hat, Inc.
___
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-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-07 Thread Mathijs Kwik
孙冰  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-07 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-07 Thread Mathijs Kwik
Indeed, that sounds like a solution.

It's a bit of a philosophical thing though, remainafterexit+oneshot
works nicely for things that represent a certain state (powersaving
on) which can be inspected and turned off.

oneshot "scripts" don't feel natural to me somehow without such a
state (which RemainAfterExit provides).
But maybe I need to alter my view on services a bit.

For now I will try your solution. Thanks




On Wed, Aug 7, 2013 at 1:02 PM, Tom Gundersen  wrote:
> On Wed, Aug 7, 2013 at 10:12 AM, Mathijs Kwik  
> 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


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  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