How to run script before the network configuration?

2

1

The unit file for that is supposed to be like that:

[Unit]
Description=@CPACK_PACKAGE_DESCRIPTION_SUMMARY@

Before=network-pre.target
Wants=network-pre.target

[Service]
Type=oneshot

ExecStart=/sbin/my-script.sh

RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

It's according to http://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/

Services that want to be run before the network is configured should place Before=network-pre.target and also set Wants=network-pre.target to pull it in.

But it stops the networking service from running at all.

Velkan

Posted 2015-11-26T10:27:11.253

Reputation: 201

Answers

3

This what worked for me:

[Unit]
Description=@CPACK_PACKAGE_DESCRIPTION_SUMMARY@

Before=network-pre.target
Wants=network-pre.target

DefaultDependencies=no
Requires=local-fs.target
After=local-fs.target

[Service]
Type=oneshot

ExecStart=/sbin/my-script.sh

RemainAfterExit=yes

[Install]
WantedBy=network.target

Velkan

Posted 2015-11-26T10:27:11.253

Reputation: 201