Systemd ignores Requires instruction when specifying a network namespace mount

Asked by Panayiotis P on 2018-10-08

One of my services creates a network namespace shortly after it starts (OpenVPN using up script). I want another service to start only if this namespace exists.

 I noticed systemd sees two mounts when this namespace gets created run-netns-vpn.mount and run-netns.mount, so I tried to put a Requires= and After= in my service file hoping that the service would only start when the mount is created. However not only the service doesn't fail, but it goes ahead starting before the mount is up.

To reproduce I created a service that sleeps for 3 seconds and creates a network namespace, then another one that depends on the namespace being mounted:

/lib/systemd/system/test-depend-mount.service

[Unit]
Description=depend on mount
After=run-netns-hello.mount
Requires=run-netns-hello.mount

[Service]
ExecStart=/sbin/ip netns exec hello echo 'hello world'

[Install]
WantedBy=multi-user.target

---
/lib/systemd/system/test-setup-mount.service

[Unit]
Description=Set mount test

[Service]
ExecStart=/usr/scripts/mount.sh

[Install]
WantedBy=multi-user.target

---
/usr/scripts/mount.sh

#!/bin/sh
sleep 3
ip netns add hello

On startup the test-depend-mount.service fails being started at 19:46:18 while the service that creates the mount starts at 19:46:21:

‚óŹ test-depend-mount.service - depend on mount
   Loaded: loaded (/lib/systemd/system/test-depend-mount.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2018-10-08 19:46:18 BST; 22min ago
  Process: 713 ExecStart=/sbin/ip netns exec hello echo hello world (code=exited, status=1/FAILURE)
 Main PID: 713 (code=exited, status=1/FAILURE)

Oct 08 19:46:18 mediabox ip[713]: Cannot open network namespace "hello": No such file or directory
Oct 08 19:46:18 mediabox systemd[1]: Started depend on mount.
Oct 08 19:46:18 mediabox systemd[1]: test-depend-mount.service: Main process exited, code=exited, status=1/FAILURE
Oct 08 19:46:18 mediabox systemd[1]: test-depend-mount.service: Failed with result 'exit-code'.

Why is this happening and is this normal?

This is on Ubuntu 18.04.1 LTS

Question information

Language:
English Edit question
Status:
Expired
For:
Ubuntu systemd Edit question
Assignee:
No assignee Edit question
Last query:
2018-10-08
Last reply:
2018-10-24
Launchpad Janitor (janitor) said : #1

This question was expired because it remained in the 'Open' state without activity for the last 15 days.