Skip to content

Commit 3e48af6

Browse files
troglobitwkz
authored andcommitted
confd: relocate auto-factory templates and prepare fail secure mode
The template and scripts for generating per-device factory-config have been spread out across the repo. This is an attempt to gather all the pieces to a single location for better overview. Parts of factory-config will be reused for the new fail secure mode, in the file failure-config. The beginnings of which are in this commit. Other changes: - cfg-bootstrap and confd-bootstrap have been collapsed into one - let gen-hostname + gen-interfaces save to /cfg instead of /etc, we've moved the /etc directory to read-only storage in /usr/share - delay start of bootstrap and sysrepo-plugind after syslogd barrier - set 'norestart' when loading startup-confg and failure-config, no point in retrying if that fails, just go to error immediately Signed-off-by: Joachim Wiberg <[email protected]>
1 parent b7c4c25 commit 3e48af6

File tree

21 files changed

+83
-48
lines changed

21 files changed

+83
-48
lines changed

board/netconf/rootfs/lib/infix/cfg-bootstrap

Lines changed: 0 additions & 35 deletions
This file was deleted.

package/confd/sysrepo.conf

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
#set DEBUG=1
22

3-
run name:bootstrap log:prio:user.notice \
4-
[S] /lib/infix/cfg-bootstrap -- Bootstrapping YANG models
3+
run name:bootstrap log:prio:user.notice <pid/syslogd> \
4+
[S] /usr/libexec/confd/bootstrap -- Bootstrapping YANG datastore
55

6-
service name:sysrepo log \
6+
service name:sysrepo log <pid/syslogd> \
77
[S12345789] sysrepo-plugind -f -p /run/sysrepo.pid -n -v3 -- Configuration daemon
88

99
# Bootstrap system with startup-config
10-
run name:startup log:prio:user.notice \
11-
[S] <pid/sysrepo> /usr/libexec/confd/confd-load.sh -b startup-config \
10+
run name:startup log:prio:user.notice norestart \
11+
[S] <pid/sysrepo> /usr/libexec/confd/load -b startup-config \
1212
-- Loading startup-config
1313

14+
# Run if loading startup-config fails for some reason
15+
run name:failure log:prio:user.critical norestart if:<run/startup/failure> \
16+
[S] <pid/sysrepo> /usr/libexec/confd/load failure-config \
17+
-- Loading failure-config
18+
1419
service name:netopeer log \
1520
[12345789] <pid/sysrepo> netopeer2-server -F -t 60 \
1621
-- NETCONF server

src/confd/Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
SUBDIRS = src yang
1+
SUBDIRS = src yang share
22
dist_doc_DATA = README.md LICENSE
3-
pkglibexec_SCRIPTS = confd-bootstrap.sh confd-load.sh
3+
pkglibexec_SCRIPTS = $(wildcard bin/*)
44
DISTCLEANFILES = *~ *.d
55
ACLOCAL_AMFLAGS = -I m4

src/confd/confd-bootstrap.sh renamed to src/confd/bin/bootstrap

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/bin/sh
2+
# Bootstrap sysrepo db with all modules required by confd
3+
#
24
# 1. Load all yang models with /cfg/factory-config
35
# 2. [ if /cfg/startup-config is missing :: copy {factory} -> /cfg/startup-config ]
46
# 3. Import /cfg/startup -> {startup} ]
@@ -9,14 +11,42 @@
911
# It's all really simple ... this script takes care of 1-4
1012
#
1113

12-
FACTORY=$1
13-
STARTUP=$2
14+
PATH=/usr/libexec/confd/:$PATH
1415
INIT_DATA=/etc/sysrepo/factory-default.json
1516
SEARCH=/usr/share/yang/modules/confd:/usr/share/yang/modules/libnetconf2:/usr/share/yang/modules/libyang:/usr/share/yang/modules/netopeer2:/usr/share/yang/modules/sysrepo
1617

17-
if [ -z "$FACTORY" -o -z "$STARTUP" ]; then
18-
echo "Missing argument to sysrepo-bootstrap.sh $FACTORY $STARTUP"
19-
exit 1
18+
[ "$FACTORY_D" ] || FACTORY_D=/usr/share/confd/factory
19+
[ "$CFG_D" ] || CFG_D=/cfg
20+
[ "$GENCFG_D" ] || GENCFG_D=/cfg/factory.d
21+
22+
FACTORY=$CFG_D/factory-config.cfg
23+
STARTUP=$CFG_D/startup-config.cfg
24+
25+
# Generate device's factory-config at first boot
26+
if [ ! -d "$GENCFG_D" ]; then
27+
mkdir -p $GENCFG_D
28+
29+
gen-hostname >$GENCFG_D/20-auto-hostname.json
30+
gen-interfaces >$GENCFG_D/20-auto-interfaces.json
31+
32+
[ -s $GENCFG_D/20-auto-hostkey.json ] || gen-hostkeys >$GENCFG_D/20-auto-hostkey.json
33+
34+
# Allow regenerating default factory-config, but keep it read-ony
35+
# to prevent it from being overwritten by mistake by users.
36+
rm -f $CFG_D/auto-factory-config.cfg
37+
# shellcheck disable=SC2046
38+
jq -s 'reduce .[] as $item ({}; . * $item)' \
39+
$(find $FACTORY_D -name '*.json') \
40+
$(find $GENCFG_D -name '*.json') \
41+
>$CFG_D/auto-factory-config.cfg
42+
chmod 444 $CFG_D/auto-factory-config.cfg
43+
44+
# TODO: Look for statically defined factory-config, based on the
45+
# system's product ID, or just custom site-specific factory.
46+
47+
# If we haven't found a better one, settle for auto-factory-config as
48+
# the system's factory-config.
49+
[ -h $FACTORY ] || ln -sf auto-factory-config.cfg $FACTORY
2050
fi
2151

2252
# Drop all pre-initialized data from netopeer2 install, then re-create
File renamed without changes.
File renamed without changes.

src/confd/confd-load.sh renamed to src/confd/bin/load

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ fi
2929
if ! sysrepocfg -v3 -I"$fn" -f json; then
3030
if eval $bootstrap; then
3131
logger -sik -p user.error "Failed bootstrapping system, reverting to Fail Secure mode!"
32-
initctl -nbq cond set fail-startup
3332
initctl -nbq runlevel 9
3433
else
3534
logger -sik -p user.error "Failed loading $fn, aborting!"

src/confd/configure.ac

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ AM_SILENT_RULES(yes)
55

66
AC_CONFIG_FILES([
77
Makefile
8+
share/Makefile
9+
share/factory/Makefile
10+
share/failure/Makefile
811
src/Makefile
912
yang/Makefile
1013
])

src/confd/share/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SUBDIRS = factory failure
2+
pkgdata_DATA = $(wildcard share/*)

0 commit comments

Comments
 (0)