fff-layer3-config: Make it easier to keep the settings in testmode

On call -t we write the pid on /tmp/configure-layer3-pid.
If the script exits from user we use trap to run the new function keep_changes()
If the connections to the router lost, the user	can run	configure-layer3 -k after
reconnect to keep changes manually

Signed-off-by: Christian Dresel <freifunk@dresel.systems>
Reviewed-by: Robert Langhammer <rlanghammer@web.de>
[wrap and rephrase exit comment, bump PKG_RELEASE]
Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
This commit is contained in:
Christian Dresel 2020-12-13 09:42:11 +01:00 committed by Adrian Schmutzler
parent 6fe053bcf7
commit 5469399112
2 changed files with 27 additions and 5 deletions

View File

@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=fff-layer3-config
PKG_RELEASE:=3
PKG_RELEASE:=4
PKG_BUILD_DIR:=$(BUILD_DIR)/fff-layer3-config

View File

@ -66,15 +66,35 @@ revert_changes() {
exit 0
}
keep_changes() {
if [ -f "/tmp/configure-layer3-pid" ]; then
echo "Keep changes"
kill -9 $(cat /tmp/configure-layer3-pid)
rm /tmp/configure-layer3-pid
# We need exit because trap in test_changes() will not stop
# the script here and revert settings otherwise
exit
else
echo "configure-layer3 -t is not running"
fi
}
test_changes() {
echo $$ > /tmp/configure-layer3-pid
trap keep_changes SIGINT SIGTERM
reload_services
sleep 5
echo "Configuration reloaded. Changes will be reverted in 200s."
echo "Kill this script to keep changes."
sleep 200
echo "Reverting changes.."
echo "Configuration reloaded. Changes will be reverted in 200s."
echo "Kill this script or use configure-layer3 -k to keep changes."
sleep 200
echo "Reverting changes.."
# on revert we must delete the pid-file
rm /tmp/configure-layer3-pid
revert_changes
reload_services
}
@ -86,6 +106,7 @@ usage() {
echo "Options:"
echo " -c: configure. No commit, no restart!"
echo " -t: test changes. Restarts services, waits up to 200s for SIGINT"
echo " -k: keep changes from test mode"
echo " -a: apply changes"
echo " -r: revert changes"
}
@ -98,6 +119,7 @@ fi
case "$1" in
-c) configure ;;
-t) test_changes ;;
-k) keep_changes ;;
-a) apply_changes ;;
-r) revert_changes ;;
*) usage; exit 1 ;;