3

I've got a systemd service which I need to have run prior to networking having started and I'm struggling with it a little. According to this: Running Services After the Network is up I need to use Before=network-pre.target, however my service isn't starting.

Dependencies:

root@server:~# systemctl list-dependencies my-script --reverse
my-script.service
● └─network-pre.target (has a red dot next to it)

The actual unit itself:

[Unit]
Description=My script
Before=network-pre.target
Wants=network-pre.target

[Service]
ExecStart=/etc/my-script
Type=oneshot
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Any suggestions?

  • One thing which does strike me is that Jessie appears to be using an init script to control networking - obviously Systemd can deal with this but I wonder if it doesn't give you the same flexibility with hooks that a fully systemd-ised networking service does? – alanbeard May 19 '15 at 11:37
0

Remove the Wants= line as you are listing something impossible to satisfy: start the service before network-pre.target but also after (Wants) it. So the unit should read as:

[Unit]
Description=My script
Before=network-pre.target

[Service]
ExecStart=/etc/my-script
Type=oneshot
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
  • freedesktop.org/wiki/Software/systemd/NetworkTarget says "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." If we don't put Wants=, it locks up (and then only starts much later) because nothing pulls network-pre.target. – Velkan Nov 26 '15 at 10:10
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.