I have this post-up script that is run by openvpn:
#!/bin/bash
echo "I am: `whoami`"
echo "Moving interface into the netns"
ip link set dev "$1" up netns hydrogenvpn mtu "$2"
echo "Listing"
ip netns ls
echo "test"
ip netns exec hydrogenvpn cat /tmp/foobar
If I run openvpn with any of these commands: service openvpn start
, /etc/init.d/openvpn start
, systemctl start openvpn@hydrogen.service
, I get this in my logs:
Sun Oct 9 11:19:15 2016 us=851109 /sbin/ip link set dev tun-hyd2 up mtu 1500
Sun Oct 9 11:19:15 2016 us=858267 /sbin/ip addr add dev tun-hyd2 10.43.43.3/24 broadcast 10.43.43.255
Sun Oct 9 11:19:15 2016 us=872474 /etc/openvpn/hydrogen_postup.sh tun-hyd2 1500 1542 10.43.43.3 255.255.255.0 init
I am: root
Moving interface into the netns
Listing
novpn (id: 1)
hydrogenvpn (id: 0)
test
setting the network namespace "hydrogenvpn" failed: Operation not permitted
However, if I run openvpn with the exact same command as systemd uses, it works:
# systemctl status openvpn@hydrogen.service | grep Process
Process: 7722 ExecStart=/usr/sbin/openvpn --daemon ovpn-%i --status /run/openvpn/%i.status 10 --cd /etc/openvpn --config /etc/openvpn/%i.conf --writepid /run/openvpn/%i.pid (code=exited, status=0/SUCCESS)
# /usr/sbin/openvpn --daemon ovpn-hydrogen --status /run/openvpn/hydrogen.status 10 --cd /etc/openvpn --config /etc/openvpn/hydrogen.conf --writepid /run/openvpn/hydrogen.pid
# tail /var/log/openvpn.log
Sun Oct 9 11:25:28 2016 us=762617 /sbin/ip addr add dev tun-hyd2 10.43.43.3/24 broadcast 10.43.43.255
Sun Oct 9 11:25:28 2016 us=767131 /etc/openvpn/hydrogen_postup.sh tun-hyd2 1500 1542 10.43.43.3 255.255.255.0 init
I am: root
Moving interface into the netns
Listing
novpn (id: 1)
hydrogenvpn (id: 0)
test
<content of /tmp/foobar>
Sun Oct 9 11:25:28 2016 us=952737 Initialization Sequence Completed
I also tried starting openvpn with systemd and then run the script manually, it works too.
Why is there a difference between the two runs? And how can I make the script work when run by openvpn started with systemd?
Versions: Debian testing, openvpn 2.3.11-2, systemd 231-9