diff --git a/package/confd/sysrepo.conf b/package/confd/sysrepo.conf index 2ac2af57..f12904a9 100644 --- a/package/confd/sysrepo.conf +++ b/package/confd/sysrepo.conf @@ -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] sysrepocfg -I/cfg/startup-config.cfg -f json \ + [S] /usr/libexec/confd/confd-load.sh -b startup-config \ -- Loading startup-config + service name:netopeer log \ [12345789] netopeer2-server -F -t 60 \ -- NETCONF server diff --git a/src/confd/Makefile.am b/src/confd/Makefile.am index 7f49515b..33fa7833 100644 --- a/src/confd/Makefile.am +++ b/src/confd/Makefile.am @@ -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 diff --git a/src/confd/confd-load.sh b/src/confd/confd-load.sh new file mode 100755 index 00000000..f2b42f81 --- /dev/null +++ b/src/confd/confd-load.sh @@ -0,0 +1,39 @@ +#!/bin/sh +# cond-load.sh [-b] +# +# Import a configuration to the sysrepo datastore using `sysrepocfg -Ifile` +# +# If the '-b' option is used we set the Finit 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."