====== Run aria2 with isolated netns with Systemd ======
git clone https://github.com/Jamesits/systemd-named-netns
cd systemd-named-netns
make install
BRIDGE=br-lan
DHCPV4=1
MACADDR=52:54:01:02:76:79
[Unit]
Requires=network-online.target netns-bridge@aria2c.service mts-Incoming.mount
After=network-online.target netns-bridge@aria2c.service mts-Incoming.mount
BindsTo=netns-bridge@aria2c.service mts-Incoming.mount
JoinsNamespaceOf=netns@aria2c.service
[Service]
PrivateNetwork=yes
SyslogIdentifier=aria2c-daemon.service
User=orzfly
Group=orzfly
ExecStart=/usr/bin/aria2c \
--enable-rpc \
--rpc-listen-all=true \
--rpc-allow-origin-all \
--rpc-listen-port=27679 \
--rpc-secret=TOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKEN \
--max-concurrent-downloads=10 \
--max-connection-per-server=16 \
--min-split-size=1M \
--split=16 \
--max-overall-download-limit=0 \
--max-download-limit=0 \
--max-overall-upload-limit=0 \
--max-upload-limit=0 \
--max-tries=1000 \
--retry-wait=5 \
--input-file=/var/lib/aria2c-daemon/session \
--save-session=/var/lib/aria2c-daemon/session \
--save-session-interval=15 \
--disk-cache=0 \
--allow-overwrite=false \
--always-resume=true \
--auto-file-renaming=false \
--continue=true \
--remote-time=true \
--lowest-speed-limit=50K \
--file-allocation=none \
--dir=/mts/Incoming/Downloads \
--seed-time=60 \
--bt-detach-seed-only=true \
--bt-request-peer-speed-limit=2M \
--bt-max-peers=100 \
--bt-max-open-files=100 \
--bt-save-metadata=true \
--user-agent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3291.0 Safari/537.36' \
--allow-piece-length-change=true
Restart=always
RestartSec=15s
[Install]
WantedBy=multi-user.target
[Unit]
Requires=network-online.target mts-Incoming.mount
After=network-online.target mts-Incoming.mount
BindsTo=mts-Incoming.mount
[Service]
SyslogIdentifier=aria2c-daemon.service
ExecStartPre=-/sbin/ip netns del ns-downloads
ExecStartPre=/sbin/ip netns add ns-downloads
ExecStartPre=/sbin/ip link add v-down-root type veth peer name v-down-peer
ExecStartPre=/sbin/ip link set v-down-peer netns ns-downloads
ExecStartPre=/sbin/brctl addif br-lan v-down-root
ExecStartPre=/sbin/ip link set v-down-root up
ExecStartPre=/sbin/ip netns exec ns-downloads /sbin/ip addr add 10.0.0.34/16 dev v-down-peer
ExecStartPre=/sbin/ip netns exec ns-downloads /sbin/ip link set v-down-peer up
ExecStartPre=/sbin/ip netns exec ns-downloads /sbin/ip link set lo up
ExecStartPre=/sbin/ip netns exec ns-downloads /sbin/ip route add default via 10.0.0.1
ExecStart=/sbin/ip netns exec ns-downloads /sbin/runuser -u orzfly -g orzfly -- /usr/bin/aria2c \
--enable-rpc \
--rpc-listen-all=true \
--rpc-allow-origin-all \
--rpc-listen-port=27679 \
--rpc-secret=TOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKEN \
--max-concurrent-downloads=10 \
--max-connection-per-server=16 \
--min-split-size=1M \
--split=16 \
--max-overall-download-limit=0 \
--max-download-limit=0 \
--max-overall-upload-limit=0 \
--max-upload-limit=0 \
--max-tries=1000 \
--retry-wait=5 \
--input-file=/var/lib/aria2c-daemon/session \
--save-session=/var/lib/aria2c-daemon/session \
--save-session-interval=15 \
--disk-cache=0 \
--allow-overwrite=false \
--always-resume=true \
--auto-file-renaming=false \
--continue=true \
--remote-time=true \
--lowest-speed-limit=50K \
--file-allocation=none \
--dir=/mts/Incoming/Downloads \
--seed-time=60 \
--bt-detach-seed-only=true \
--bt-request-peer-speed-limit=2M \
--bt-max-peers=100 \
--bt-max-open-files=100 \
--bt-save-metadata=true \
--user-agent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3291.0 Safari/537.36' \
--allow-piece-length-change=true
ExecStopPost=-/sbin/ip netns del ns-downloads
Restart=always
RestartSec=15s
[Install]
WantedBy=multi-user.target
===== See Alsos =====
- [[topics:ip-netns-cheatsheet]]
- https://github.com/Jamesits/systemd-named-netns
- https://gist.github.com/rudylacrete/dcd9779175fe18731852
{{tag>netns systemd aria2}}