[systemd-devel] Starting a service before any networking
Jan Hugo Prins
jhp at jhprins.org
Wed Sep 27 08:32:34 UTC 2023
I think the main problem you are running into is the DefaultDependencies
option. When this is set to on, several default dependencies are being
enforced which make sure that at least a basic system is up and running
before anything else is started. When you want to start something before
the basic system is up and running and want, for example, just to be
sure that all the filesystems are mounted, you can do something like this:
[Unit]
DefaultDependencies=no
After=local-fs.service
Before=dependent_service1.service dependent_service2.service
Conflicts=shutdown.target initrd-switch-root.target
[Service]
Type=oneshot
TimeoutStartSec=600
RemainAfterExit=yes
ExecStart=<your startup script>
[Install]
WantedBy=sysinit.target
Best regards,
Jan Hugo Prins
Op 26-09-2023 om 12:50 schreef Mark Rogers:
> I'm sure this is trivial but I've gone round in circles without success.
>
> I have a script which reads from an SQLite database and generates
> various system configuration files - at the moment these are
> dhcpcd.conf and wpa_supplicant.conf but this might grow in future.
>
> As such the only dependency the script has is that the filesystem is
> up and running. But the script must complete before anything that the
> script manages the configuration file for.
>
> My current unit looks like this:
> [Unit]
> Before=networking.service
> After=local-fs.target
>
> [Service]
> Type=oneshot
> ExectStart=/path/to/script
>
> [Install]
> RequiredBy=network.target
>
> Where am I going wrong and what is the right way to do this?
>
> I've also tried Before=network-pre.target and Wants=network-pre.target
> without success - it was that not working that set me off trying to
> fix it.
> --
> Mark Rogers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20230927/b7258e94/attachment-0001.htm>
More information about the systemd-devel
mailing list