mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-30 04:33:00 +02:00
Refactor boot mode handling
With the recent `if:<cond>` addition to Finit we can simplify a lot of the logic for disabling and enabling features in Infix. Standardizing on conditions that Finit provides. We create boot/netconf, boot/etc, and boot/profinet conditions early, after all filesystems have been mounted (and cleaned), so they are all set before Finit loads its configuration files in runlevel S. The default is still to boot into a managed NETCONF mode, since the end goal remains to integrate PROFINET as yet another service. The other mode, native /etc, should then be the only exception. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
run [S] /lib/infix/nameif -- Probing network interfaces
|
||||
run [S] /lib/infix/swup --
|
||||
run if:<!boot/netconf> [S] /lib/infix/swup --
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/lib/infix/use-etc && exit 0
|
||||
|
||||
# This is a managed node, ignore all default configuration...
|
||||
rm -f /etc/rc.local
|
||||
rm -f /etc/rc.local
|
||||
rm -rf /etc/finit.d/enabled/*.conf
|
||||
rm -rf /etc/network/interfaces*
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ mount_rw()
|
||||
mountpoint -q "/$1" && return 0
|
||||
|
||||
# TODO: Also look for UBI partitions
|
||||
mount LABEL="$1" && return 0
|
||||
mount LABEL="$1" 2>/dev/null && return 0
|
||||
|
||||
return 1
|
||||
}
|
||||
@@ -49,29 +49,6 @@ mount_overlay()
|
||||
-o lowerdir="$dst",upperdir="$u",workdir="$w"
|
||||
}
|
||||
|
||||
use_etc()
|
||||
{
|
||||
if [ -f /mnt/cfg/infix/.use_etc ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Finit's condition system is not yet bootstrapped when /etc/fstab
|
||||
# is parsed, so we have to manually check for the boot/etc
|
||||
# condition.
|
||||
awk '
|
||||
$0 == "finit.cond" {
|
||||
cond=1;
|
||||
next;
|
||||
}
|
||||
cond == 1 {
|
||||
use_etc = index($0, "etc") != 0;
|
||||
}
|
||||
END {
|
||||
exit(use_etc ? 0 : 1);
|
||||
}
|
||||
' /proc/1/cmdline
|
||||
}
|
||||
|
||||
# Fall back to console logging if sysklogd is too old
|
||||
if ! logger -? |grep -q "Log to kernel"; then
|
||||
opt="-c"
|
||||
@@ -111,16 +88,8 @@ else
|
||||
sync
|
||||
fi
|
||||
|
||||
# Report to the setup tool the current boot mode
|
||||
if use_etc; then
|
||||
if /lib/infix/use-etc; then
|
||||
etcsrc=/mnt/cfg
|
||||
if [ -f /mnt/cfg/infix/.use_etc ]; then
|
||||
cat /mnt/cfg/infix/.use_etc > /tmp/.boot_mode
|
||||
else
|
||||
echo "native /etc" > /tmp/.boot_mode
|
||||
fi
|
||||
else
|
||||
echo "NETCONF" > /tmp/.boot_mode
|
||||
fi
|
||||
|
||||
# Ensure that all users in wheel can create the .reset file
|
||||
@@ -128,7 +97,6 @@ else
|
||||
chgrp wheel /mnt/cfg/infix
|
||||
fi
|
||||
|
||||
|
||||
mount_overlay cfg $cfgsrc /cfg
|
||||
mount_overlay etc $etcsrc /etc
|
||||
mount_overlay home $cfgsrc /home
|
||||
|
||||
@@ -1,15 +1,7 @@
|
||||
#!/bin/sh
|
||||
# Only runs in native /etc and PROFINET nodes.
|
||||
|
||||
# Only create a default config on unmanaged nodes.
|
||||
if ! /lib/infix/use-etc; then
|
||||
initctl cond set netconf
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# PROFINET is a variant of native /etc, make sure to
|
||||
# enable it and disable the default LLDP daemon.
|
||||
if grep -qi profinet /mnt/cfg/infix/.use_etc; then
|
||||
initctl enable profeth
|
||||
if initctl cond get boot/profinet; then
|
||||
initctl enable snmpd
|
||||
initctl disable lldpd
|
||||
fi
|
||||
|
||||
@@ -1,6 +1,21 @@
|
||||
#!/bin/sh
|
||||
|
||||
[ -f /mnt/cfg/infix/.use_etc ] && exit 0
|
||||
initctl cond get boot/etc && exit 0
|
||||
if [ -f /mnt/cfg/infix/.use_etc ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
exit 1
|
||||
# Finit's condition system may not yet be bootstrapped when this script
|
||||
# is called, e.g., when /etc/fstab is parsed, so we have to manually
|
||||
# check for the boot/etc condition.
|
||||
awk '
|
||||
$0 == "finit.cond" {
|
||||
cond=1;
|
||||
next;
|
||||
}
|
||||
cond == 1 {
|
||||
use_etc = index($0, "etc") != 0;
|
||||
}
|
||||
END {
|
||||
exit(use_etc ? 0 : 1);
|
||||
}
|
||||
' /proc/1/cmdline
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#!/bin/sh
|
||||
# Override boot mode based on user input from setup tool
|
||||
|
||||
set_cond()
|
||||
{
|
||||
mkdir -p /run/finit/cond/boot
|
||||
ln -s /run/finit/cond/reconf "/run/finit/cond/boot/$1"
|
||||
}
|
||||
|
||||
# Report to the setup and show tools the current boot mode
|
||||
if /lib/infix/use-etc; then
|
||||
if [ -f /mnt/cfg/infix/.use_etc ]; then
|
||||
cat /mnt/cfg/infix/.use_etc > /tmp/.boot_mode
|
||||
if grep -qi profinet /mnt/cfg/infix/.use_etc; then
|
||||
set_cond profinet
|
||||
else
|
||||
set_cond etc
|
||||
fi
|
||||
else
|
||||
echo "native /etc" > /tmp/.boot_mode
|
||||
set_cond etc
|
||||
fi
|
||||
else
|
||||
echo "NETCONF" > /tmp/.boot_mode
|
||||
set_cond netconf
|
||||
fi
|
||||
@@ -1,5 +1,5 @@
|
||||
run if:<usr/netconf> [S] /lib/infix/clean-etc --
|
||||
run if:<usr/netconf> [S] /lib/infix/prep-db --
|
||||
run if:<usr/netconf> [S] :boot clixon_backend -F -1 -s startup -- Loading startup configuration
|
||||
run if:<boot/netconf> [S] /lib/infix/clean-etc --
|
||||
run if:<boot/netconf> [S] /lib/infix/prep-db --
|
||||
run if:<boot/netconf> [S] :boot clixon_backend -F -1 -s startup -- Loading startup configuration
|
||||
|
||||
service if:<usr/netconf> [12345789] clixon_backend -F -s none -- Configuration daemon
|
||||
service if:<boot/netconf> [12345789] clixon_backend -F -s none -- Configuration daemon
|
||||
|
||||
@@ -151,6 +151,7 @@ endif
|
||||
ifeq ($(BR2_PACKAGE_PROFETH),y)
|
||||
define SKELETON_INIT_FINIT_SET_PROFETH
|
||||
cp $(SKELETON_INIT_FINIT_AVAILABLE)/profeth.conf $(FINIT_D)/available/
|
||||
ln -sf ../available/profeth.conf $(FINIT_D)/enabled/
|
||||
endef
|
||||
SKELETON_INIT_FINIT_TARGET_FINALIZE_HOOKS += SKELETON_INIT_FINIT_SET_PROFETH
|
||||
endif
|
||||
|
||||
Reference in New Issue
Block a user