[systemd-devel] Question about changing systemd target during boot

Svetoslav Iliev swetli at telco.com
Mon Aug 1 09:27:15 UTC 2016


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/

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.

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20160801/7b8cbc47/attachment.html>


More information about the systemd-devel mailing list