1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/etc/systemd/system/service-a.service

[Unit]
Description=Start network namespace and add veth

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/root/create-ns.sh

ExecStop=/usr/bin/brctl delif br0 veth0
ExecStop=/usr/bin/ip link del veth0 type veth peer name veth1
ExecStop=/usr/bin/ip netns del servicens


[Install]
WantedBy=multi-user.target


/etc/systemd/system/service-b.service
[Unit]
Description=Start vpn
Requires=service-a.service
After=service-a.service

[Service]
ExecStart=/usr/bin/ip netns exec servicens /usr/bin/openvpn --config /etc/openvpn/service-b.conf --writepid /var/run/serviceb-openvpn.pid --daemon
Type=forking
Restart=on-abort
PIDFile=/var/run/serviceb-openvpn.pid

[Install]
WantedBy=multi-user.target

###
#systemctrl enable service-b