You are not logged in.
Hi everyone,
Let's say I have an program that is absolutely essential to my system, and I want it to run before netctl even tries initialising my network connection (in fact, I want the network to be unavailable until the program has finished its execution). I _always_ want to see the program's output on the console, and if it exits with a non-zero exit code, I want the whole boot process to be aborted (or at least all of netctl's units to be disabled). Is this possible in systemd?
Last edited by popoffka (2014-04-18 13:07:09)
Offline
Hi everyone,
Hi.
Let's say I have an program that is absolutely essential to my system, ...
Sure.
and I want it to run before netctl even tries initialising my network connection (in fact, I want the network to be unavailable until the program has finished its execution).
Use 'Before=' in your unit file. Make sure it does not fork.
I _always_ want to see the program's output on the console,
Pipe it's output to /dev/console directly. Maybe there is a cleaner why, I'm not sure. SystemD actually supports the redirect directive in it's native language (nice).
and if it exits with a non-zero exit code, I want the whole boot process to be aborted (or at least all of netctl's units to be disabled)
Use 'RequiredBy=' in your unit file. That could be used to prevent netctl from starting. Preventing the whole boot isn't a bit drastic isn't it?
. Is this possible in systemd?
Yes. Consult the systemd.service and systemd.unit manpages.
fs/super.c : "Self-destruct in 5 seconds. Have a nice day...\n",
Offline
Thanks for your assistance, Rexilion!
I created a .service file like this:
[Unit]
Before=network.target
Before=netctl-auto@.service
Before=netctl-ifplugd@.service
Before=multi-user.target
[Service]
Type=oneshot
ExecStart=<command>
StandardOutput=journal+console
[Install]
RequiredBy=network.target
RequiredBy=netctl-auto@.service
RequiredBy=netctl-ifplugd@.service
RequiredBy=multi-user.target
However, even if the command fails, the system still continues to boot, and netctl-auto@ still starts (although systemd logs things like "Dependency failed for Network"). Am I missing something here?
Offline
Cool, never knew about systemd.exec . Thank you.
You might want to add StandardError= as well. Otherwise you will not see errormessages on your console.
netctl-auto@ and netctl-ifplugd@ are services that are supposed to be instantiated and hence are not ran directly. You need to add something like netctl-auto@wlan0 for each interface. I'm not aware of any other service that does this for networking as a whole. You could create a service file that polls for a default route and make that fail / succeed. Then other services can depend on that for network connectivity.
Preventing the system from booting would involve issueing a shutdown command the moment this service fails. You could use 'OnFailure=' for this. I'm surprised you did not find that directive.
Last edited by Rexilion (2014-04-18 12:32:00)
fs/super.c : "Self-destruct in 5 seconds. Have a nice day...\n",
Offline
Oh. Yeah, appending the names of particular interfaces to netctl-auto@ and netctl-ifplugd@ solved the issue. Damn, and I'd hoped systemd was smarter.
I decided that halting the boot process is too dramatic indeed and simply disabling the network is enough, so my issue is resolved completely now. Thanks again for your assistance!
Offline
You could create a catch all network-active.service that polls /etc/resolv.conf or for a default route to. This will hook up just one service file and not one for each interface.
Glad I could assist you!
fs/super.c : "Self-destruct in 5 seconds. Have a nice day...\n",
Offline