Lets assume our IPVS table is saved under /usr/local/etc/ipvs-table
(e.g. as the output of ipvsadm -S
).
Create the service file at /etc/systemd/system/restore-ipvs-table.service
:
[Unit]
Description=Restore IPVS table from file
After=network.target
[Service]
Type=oneshot
# The dump file is the output of: ipvsadm -S
Environment=DUMP_FILE=/usr/local/etc/ipvs-table
ExecStart=/usr/local/bin/restore-ipvs-table.sh
StandardOutput=journal
[Install]
WantedBy=multi-user.target
Create the oneshot
script at /usr/local/bin/restore-ipvs-table.sh
:
#!/bin/bash
set -e
test -n "${DUMP_FILE}"
test -f "${DUMP_FILE}"
ipvsadm -C
cat ${DUMP_FILE} | ipvsadm -R