<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi all,<br>
<br>
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:<br>
<br>
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).<br>
<br>
So here goes what I've done:<br>
<br>
1. Create a service and put it in the network-online.target:<br>
<br>
/etc/systemd/system/change-target.service:<br>
<i>[Unit]</i><i><br>
</i><i>Description=Change Target </i><i><br>
</i><i>Wants=network-online.target</i><i><br>
</i><i>After=network-online.target</i><i><br>
</i><i><br>
</i><i>[Service]</i><i><br>
</i><i>Type=oneshot</i><i><br>
</i><i>ExecStart=/tmp/script.sh</i><i><br>
</i><i>TimeoutSec=60s</i><i><br>
</i><i><br>
</i><i>[Install]</i><i><br>
</i><i>WantedBy=network-online.target</i><br>
<br>
2. Create two new targets:<br>
/etc/systemd/system/a.target:<br>
<i>[Unit]</i><i><br>
</i><i>Description=A Target</i><i><br>
</i><i>Requires=multi-user.target</i><i><br>
</i><i>After=multi-user.target</i><i><br>
</i><i>AllowIsolate=yes</i><i><br>
</i><i>Conflicts=b.target</i><br>
<br>
/etc/systemd/system/b.target:<br>
<i>[Unit]</i><i><br>
</i><i>Description=B Target</i><i><br>
</i><i>Requires=multi-user.target</i><i><br>
</i><i>After=multi-user.target</i><i><br>
</i><i>AllowIsolate=yes</i><i><br>
</i><i>Conflicts=a.target</i><br>
<br>
3. The contents of script.sh<br>
blah blah: do some work and based on that do either<br>
systemctl isolate a.target || systemctl isolate b.target<br>
<br>
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.<br>
<br>
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>
<br>
---<br>
BR,<br>
<br>
Swetli<br>
<br>
</body>
</html>