You are not logged in.
I'm trying to run dhcpcd in a network namespace (test) and place the pid file under /run/dhcpcd-test to avoid interface name conflicts.
Here is my service file:
[Unit]
Description=dhcpcd on %i in netns test service
After=netns-devices@test.service
BindsTo=netns-devices@test.service
JoinsNamespaceOf=netns@test.service
[Service]
Type=forking
RuntimeDirectory=dhcpcd-test
BindPaths=/run/dhcpcd-test:/run
PIDFile=/run/dhcpcd-test/dhcpcd-%i.pid
PrivateNetwork=yes
PrivateTmp=yes
ExecStart=/usr/bin/dhcpcd -q -4 -w %I
ExecStop=/usr/bin/dhcpcd -x %i
[Install]
WantedBy=multi-user.target
netns@test.service runs with PrivateNetwork=yes and creates the test network namespace and seems to be working fine.
netns-devices@test.service sets-up some devices in the network namespace and also seems to be working fine:
# ip -n test l
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: mb-test: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
link/ether b6:46:21:14:a4:a7 brd ff:ff:ff:ff:ff:ff link-netnsid 0
3: br-test: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/ether 4e:96:c4:33:64:8e brd ff:ff:ff:ff:ff:ff
4: tun-test: <POINTOPOINT,MULTICAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 500
link/none
but running the service fails and seems to have an issue with the PID file.
# systemctl start netns-test-dhcpcd@mb-test.service
Job for netns-test-dhcpcd@mb-test.service failed because the control process exited with error code.
See "systemctl status netns-test-dhcpcd@mb-test.service" and "journalctl -xe" for details.
# systemctl status netns-test-dhcpcd@mb-net0.service
● netns-test-test@mb-net0.service - dhcpcd on mb-test in netns test service
Loaded: loaded (/etc/systemd/system/netns-test-dhcpcd@.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Sun 2018-10-14 23:24:57 PDT; 52s ago
Process: 27888 ExecStart=/usr/bin/dhcpcd -q -4 -w mb/test (code=exited, status=1/FAILURE)
systemd[1]: Starting dhcpcd on mb-test in netns test service...
dhcpcd[27888]: main: pidfile_lock: No such file or directory
systemd[1]: netns-test-dhcpcd@mb-test.service: Control process exited, code=exited status=1
systemd[1]: netns-test-dhcpcd@mb-test.service: Failed with result 'exit-code'.
systemd[1]: Failed to start dhcpcd on mb-test in netns test service.
Does anyone have any suggestions on how I might be able to fix the service file?
UPDATE: See my solution below.
Last edited by emphire (2018-10-17 00:44:33)
Offline
You can't change the location of the pidfile in dhcpcd.
I have no idea what a "network namespace" is, but I imagine it's the chroot equivalent for networking.
As such, why not run dhcpcd in a chroot to solve this?
Offline
Thanks @rsmarples,
Yes, network namespaces are basically a chroot for networking. I was hoping that that binding mounting /run/dhcpcd-test to /run in the service would take care of moving the PID file:
RuntimeDirectory=dhcpcd-test
BindPaths=/run/dhcpcd-test:/run
I might be doing this wrong but, as I understand, it should create a directory /run/dhcpcd-test and map it to /run for that service. I was hoping to run the instance of dhcpcd without having to do a full chroot setup as it's a bit easier for maintenance / updates. Please let me know if you have any other suggestions.
Offline
I did a small test and it looks like the bind mount should work so I'm not sure what's causing the dhcpcd error.
#/etc/systemd/system/bindtest.service
[Service]
Type=oneshot
RemainAfterExit=yes
RuntimeDirectory=bindtest
BindPaths=/run/bindtest:/run
ExecStart=touch /run/bindtest.test
It looks like setting RuntimeDirectory=bindtest and BindPaths=/run/bindtest:/run is creating and binding the run directory for the service as the service does create the file at /run/bindtest/bindtest.test:
# ls /run/bindtest
ls: cannot access '/run/bindtest': No such file or directory
# systemctl start bindtest.serivice
# ls /run/bindtest/
bindtest bindtest.test
Offline
I managed to get it working. It turns out dhcpcd appends "-4" to the pidfile name if you specify ipv4 only.
Here is my working service file:
[Unit]
Description=dhcpcd on %i in netns piagate service
After=netns-devices@piagate.service
BindsTo=netns-devices@piagate.service
JoinsNamespaceOf=netns@piagate.service
[Service]
Type=forking
RuntimeDirectory=dhcpcd-piagate
BindPaths=/run/dhcpcd-piagate:/run
BindPaths=/run/netns /run/systemd /run/udev
BindPaths=/etc/netns/piagate/resolv.conf:/run/systemd/resolve/resolv.conf
BindPaths=/etc/netns/piagate/hosts:/etc/hosts
PIDFile=/run/dhcpcd-piagate/dhcpcd-%i-4.pid
PrivateNetwork=yes
PrivateTmp=yes
ExecStart=/usr/bin/dhcpcd -q -4 -w %i
ExecStop=/usr/bin/dhcpcd -4 -x %i
[Install]
WantedBy=multi-user.target
Offline