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

2013-08-07 Thread Mathijs Kwik
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)
- 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


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


[systemd-devel] Unit that depends on A or B

2016-06-02 Thread Mathijs Kwik

Hi all,

On my system, I can setup 2 VPN connections, which are mutually 
exclusive as they reach the same subnet for the most part.
Let's call these A and B. A is faster than B, but B gives access to some 
extra subnets.


Now, I have a unit(some-dht.service) that needs a VPN connection but 
does not really care which one.

Another unit (super-secret.service) really needs VPN B.

What I would like is the following:
If no VPN is up, starting some-dht.service should start VPN A (as it's 
the fastest).
But if B is already up, starting some-dht.service should not try to 
switch to VPN A, as that brings down B and super-secret.service with it.
Of course if A or B stops, some-dht.service and super-secret.service 
should both stop as well.


Having 2 copies of some-dht (some-dht-at-A.service, 
some-dht-at-B.service) is a no-go, as that would bubble up into my 
top-level targets and scale badly when I need another choice-construct 
like this.

(at-work-with-vpn-A-and-soundcard-X.target)
(at-work-with-vpn-A-and-soundcard-Y.target)
(at-work-with-vpn-B-and-soundcard-X.target)
(at-work-with-vpn-B-and-soundcard-Y.target)

Not mentioning the requirement (on A or B) to systemd and resorting to 
some script that decides which units to bring up does not sound like a 
solution either.


Can I achieve this in some way?

regards,
Mathijs

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