[systemd-devel] Question about changing systemd target during boot
Andrei Borzenkov
arvidjaar at gmail.com
Mon Aug 1 10:59:44 UTC 2016
On Mon, Aug 1, 2016 at 12:27 PM, Svetoslav Iliev <swetli at telco.com> wrote:
> Hi all,
>
> I've been recently searching through internet for a possible solution for
> this but so far without success and I'm still not sure if it is even
> possible. Basically what I'm trying to do:
>
> During system boot, after the network-online target I want to execute a
> script which changes the current target ( or put simply just to boot in
> another target, not in the default multi-user.target).
>
> So here goes what I've done:
>
> 1. Create a service and put it in the network-online.target:
>
> /etc/systemd/system/change-target.service:
> [Unit]
> Description=Change Target
> Wants=network-online.target
> After=network-online.target
>
> [Service]
> Type=oneshot
> ExecStart=/tmp/script.sh
> TimeoutSec=60s
>
> [Install]
> WantedBy=network-online.target
>
This unit have conflicting requirements - on one hand it is
After=network-online.target, OTOH WantedBy=network-online.target
implies Before=network-online.target. Systemd breaks cycle here, but
what is correct?
Also network-online.target is intended to be passive, not pulling
anything, rather being pulled by other units.
> 2. Create two new targets:
> /etc/systemd/system/a.target:
> [Unit]
> Description=A Target
> Requires=multi-user.target
> After=multi-user.target
> AllowIsolate=yes
> Conflicts=b.target
>
> /etc/systemd/system/b.target:
> [Unit]
> Description=B Target
> Requires=multi-user.target
> After=multi-user.target
> AllowIsolate=yes
> Conflicts=a.target
>
> 3. The contents of script.sh
> blah blah: do some work and based on that do either
> systemctl isolate a.target || systemctl isolate b.target
>
> Note I've also edited the multi-user.target to depend on the the
> change-target.service by putting the latter in the former's wants and after
> sections. I've tried many things and every time it failed. The problem is
> that the systemd should "wait" for the execution of script.sh before
> continuing with the boot process.
>
This is virtually impossible currently. Nor is this requirement clear.
If systemd is as far as networking large part of startup sequence is
already processed. So how exactly you define units that can be started
before your switch and units that must wait?
> The question is - is what I'm trying to achieve even possible or systemd
> should boot in a certain target before changing to another one ? If possible
> please advise what I'm doing wrong since I'm pretty lost..
>
> ---
> BR,
>
> Swetli
>
>
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/systemd-devel
>
More information about the systemd-devel
mailing list