summaryrefslogtreecommitdiff
path: root/files/my-netns@.service
blob: 74805e33150e36c6d742aefeb649faa2ad4f8849 (plain)
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
[Unit]
Description=Named network namespace %I
Documentation=https://github.com/Jamesits/systemd-named-netns

After=network-pre.target
Before=network.target network-online.target

[Install]
WantedBy=network-online.target
WantedBy=multi-user.target

[Service]
Type=oneshot
RemainAfterExit=yes

# precaution
ExecStartPre=-/usr/bin/env ip netns delete %I

# set up netns and bind it to this service
ExecStart=/usr/bin/flock --no-fork -- /var/run/netns.lock /usr/bin/env ip netns add %I
ExecStart=/usr/bin/env ip link add veth%I type veth peer vethpeer%I netns %I
ExecStart=/usr/bin/env ip link set veth%I up
ExecStart=/usr/bin/env ip netns exec %I ip link set vethpeer%I name eth0
ExecStart=/usr/bin/env ip netns exec %I ip link set lo up
ExecStart=/usr/bin/env ip netns exec %I ip link set eth0 up

# remove the netns
ExecStop=/usr/bin/env ip link del veth%I
ExecStop=/usr/bin/env ip netns delete %I