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:


Description=depend on mount

ExecStart=/sbin/ip netns exec hello echo 'hello world'



Description=Set mount test




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

English Edit question
Ubuntu systemd Edit question
No assignee Edit question
Last query:
Last reply:
Launchpad Janitor (janitor) said : #1

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