confd: load startup-config with a new wrapper to detect errors

The new confd-load.sh script handles bootstrapping Infix using startup-config
or a failure-config (see later commits) on error.

When used with the -b (bootstrap) option, and failure to load the give file,
the script sets a Finit condition and goes to runlevel 9.  The condition can
be used to trigger loading of a failure-config to go to a Fail Secure mode.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2023-10-09 10:41:46 +02:00
committed by Tobias Waldekranz
parent 8152df445b
commit e85bc8223b
3 changed files with 48 additions and 3 deletions
+8 -2
View File
@@ -1,10 +1,16 @@
#set DEBUG=1
run name:bootstrap log:prio:user.notice \
[S] /lib/infix/cfg-bootstrap -- Bootstrapping YANG models
service name:sysrepo log \
[S12345789] sysrepo-plugind -f -p /run/sysrepo.pid -n -- Configuration daemon
[S12345789] sysrepo-plugind -f -p /run/sysrepo.pid -n -v3 -- Configuration daemon
# Bootstrap system with startup-config
run name:startup log:prio:user.notice \
[S] <pid/sysrepo> sysrepocfg -I/cfg/startup-config.cfg -f json \
[S] <pid/sysrepo> /usr/libexec/confd/confd-load.sh -b startup-config \
-- Loading startup-config
service name:netopeer log \
[12345789] <pid/sysrepo> netopeer2-server -F -t 60 \
-- NETCONF server
+1 -1
View File
@@ -1,5 +1,5 @@
SUBDIRS = src yang
dist_doc_DATA = README.md LICENSE
pkglibexec_SCRIPTS = confd-bootstrap.sh
pkglibexec_SCRIPTS = confd-bootstrap.sh confd-load.sh
DISTCLEANFILES = *~ *.d
ACLOCAL_AMFLAGS = -I m4
+39
View File
@@ -0,0 +1,39 @@
#!/bin/sh
# cond-load.sh [-b] <startup-config | failure-config>
#
# Import a configuration to the sysrepo datastore using `sysrepocfg -Ifile`
#
# If the '-b' option is used we set the Finit <usr/bootstrap> condition if
# sysrepocfg returns OK. This to be able to detect and trigger the Infix
# Fail Secure Mode at boot.
#
set -e
if [ "$1" = "-b" ]; then
bootstrap=true
shift
else
bootstrap=false
fi
config=$1
fn=/cfg/${config}.cfg
if [ ! -f "$fn" ]; then
if [ ! -f "$config" ]; then
logger -sik -p user.error "No such file, $fn, aborting!"
exit 1
fi
fn=$config
fi
if ! sysrepocfg -v3 -I"$fn" -f json; then
if eval $bootstrap; then
logger -sik -p user.error "Failed bootstrapping system, reverting to Fail Secure mode!"
initctl -nbq cond set fail-startup
initctl -nbq runlevel 9
else
logger -sik -p user.error "Failed loading $fn, aborting!"
fi
exit 1
fi
logger -sik -p user.notice "Loaded $fn successfully."