From 576786c97065c8e5638e9e0a7cad688175cd3746 Mon Sep 17 00:00:00 2001 From: Kim Date: Sun, 14 Oct 2018 21:33:06 +0200 Subject: Rework vyos router init (#11) * Add a systemd vyos.target and split the vyatta-router init script to multiple systemd scripts. * remove ref to cloud-init * Remove vyatta-router init and rename vyatta-router to vyos-initialize. * Install files to correct dirs * try to fix systemd boot issues * Update script names run config load in background to not block systemd * Prevent cat: write error: Broken pipe * Rework vyos startup * add systemd to Makefile.am * Update script name * Fix inclusion of getty conf * Fix indentation --- Makefile.am | 11 +- debian/rules | 7 +- debian/vyatta-cfg.install | 2 + debian/vyatta-cfg.postinst.in | 3 +- debian/vyatta-cfg.postrm.in | 4 +- debian/vyatta-cfg.vyatta-router.service | 22 --- debian/vyatta-cfg.vyos-router.service | 18 +++ debian/vyatta-cfg.vyos.target | 3 + etc/init.d/vyatta-router | 250 ------------------------------- etc/systemd/aftervyos.conf | 3 + scripts/init/vyos-config | 18 +++ scripts/init/vyos-router | 244 ++++++++++++++++++++++++++++++ scripts/system-generators/vyos-generator | 94 ++++++++++++ scripts/vyatta-boot-config-loader | 5 +- 14 files changed, 405 insertions(+), 279 deletions(-) delete mode 100644 debian/vyatta-cfg.vyatta-router.service create mode 100644 debian/vyatta-cfg.vyos-router.service create mode 100644 debian/vyatta-cfg.vyos.target delete mode 100755 etc/init.d/vyatta-router create mode 100644 etc/systemd/aftervyos.conf create mode 100755 scripts/init/vyos-config create mode 100755 scripts/init/vyos-router create mode 100755 scripts/system-generators/vyos-generator diff --git a/Makefile.am b/Makefile.am index f1b98aa..81c1b1b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,7 +22,6 @@ AM_LFLAGS = --prefix=yy_`basename $* .l`_ -olex.yy.c ACLOCAL_AMFLAGS = -I m4 completion_DATA = etc/bash_completion.d/vyatta-cfg -initd_SCRIPTS = etc/init.d/vyatta-router dhcphook_SCRIPTS = scripts/vyatta-dhclient-hook logrotate_DATA = etc/logrotate.d/vyatta-config-logs logrotate_DATA += etc/logrotate.d/auth @@ -32,6 +31,16 @@ interp_DATA = functions/interpreter/vyatta-cfg-run wrapperdir = /opt/vyatta/etc/functions/ wrapper_DATA = functions/wrapper/script-template +systemdinitdir = /usr/libexec/vyos/init/ +systemdinit_SCRIPTS = scripts/init/vyos-router +systemdinit_SCRIPTS += scripts/init/vyos-config + +systemdgeneratordir = /lib/systemd/system-generators/ +systemdgenerator_SCRIPTS = scripts/system-generators/vyos-generator + +systemdgettydir = /etc/systemd/system/getty@.service.d/ +systemdgetty_DATA = etc/systemd/aftervyos.conf + src/cparse/cparse.cpp: src/cparse/cparse.ypp src/cparse/cparse_def.h bison -p cparse_ --defines=src/cparse/cparse.h -o $@ $< diff --git a/debian/rules b/debian/rules index eab1375..2603b2d 100755 --- a/debian/rules +++ b/debian/rules @@ -1,5 +1,9 @@ #!/usr/bin/make -f +DIR := debian/vyatta-cfg +VYOS_LIBEXEC_DIR := usr/libexec/vyos +SYSTEM_GENERATORS_DIR := lib/systemd/system-generators + export DH_OPTIONS ## uncomment to enable hardening @@ -44,5 +48,6 @@ override_dh_install: dh_install $(inst_opts) override_dh_systemd_enable: - dh_systemd_enable -pvyatta-cfg --name vyatta-router vyatta-router.service + dh_systemd_enable -pvyatta-cfg --name vyos-router vyos-router.service + dh_systemd_enable -pvyatta-cfg --name vyos vyos.target diff --git a/debian/vyatta-cfg.install b/debian/vyatta-cfg.install index 8c9aca2..abbe975 100644 --- a/debian/vyatta-cfg.install +++ b/debian/vyatta-cfg.install @@ -4,3 +4,5 @@ opt/vyatta/share/vyatta-cfg/functions opt/vyatta/sbin opt/vyatta/etc bin +usr/libexec +lib diff --git a/debian/vyatta-cfg.postinst.in b/debian/vyatta-cfg.postinst.in index fc9b07b..a741b62 100644 --- a/debian/vyatta-cfg.postinst.in +++ b/debian/vyatta-cfg.postinst.in @@ -16,8 +16,7 @@ for dir in $sysconfdir/config $prefix/config; do chgrp vyattacfg $dir 2>/dev/null done -update-rc.d vyatta-router defaults 90 >/dev/null -systemctl enable vyatta-router.service >/dev/null +systemctl enable vyos-router.service >/dev/null # capability stuff for bin in my_cli_bin my_cli_shell_api; do diff --git a/debian/vyatta-cfg.postrm.in b/debian/vyatta-cfg.postrm.in index b184f20..b4cbc80 100644 --- a/debian/vyatta-cfg.postrm.in +++ b/debian/vyatta-cfg.postrm.in @@ -1,7 +1,7 @@ #!/bin/bash -e if [ "$1" = "purge" ]; then - update-rc.d vyatta-router remove >/dev/null || exit $? - systemctl disable vyatta-router.service >/dev/null || exit $? + systemctl disable vyos-initialize.service >/dev/null || exit $? + systemctl disable vyos-config-load.service >/dev/null || exit $? fi diff --git a/debian/vyatta-cfg.vyatta-router.service b/debian/vyatta-cfg.vyatta-router.service deleted file mode 100644 index 0ecf6f4..0000000 --- a/debian/vyatta-cfg.vyatta-router.service +++ /dev/null @@ -1,22 +0,0 @@ -[Unit] -SourcePath=/etc/init.d/vyatta-router -Description=VyOS Router -Before=runlevel2.target runlevel3.target runlevel4.target runlevel5.target shutdown.target getty@tty1.service getty@tty2.service getty@rrt3.service getty@tty4.service getty@tty5.service getty@tty6.service -After=systemd-journald-dev-log.socket time-sync.target local-fs.target -Conflicts=shutdown.target - -[Service] -Type=oneshot -Restart=no -TimeoutSec=5min -IgnoreSIGPIPE=no -KillMode=process -GuessMainPID=no -RemainAfterExit=yes -SysVStartPriority=4 -ExecStart=/etc/init.d/vyatta-router start -ExecStop=/etc/init.d/vyatta-router stop -StandardOutput=journal+console - -[Install] -WantedBy=multi-user.target diff --git a/debian/vyatta-cfg.vyos-router.service b/debian/vyatta-cfg.vyos-router.service new file mode 100644 index 0000000..9cc6f12 --- /dev/null +++ b/debian/vyatta-cfg.vyos-router.service @@ -0,0 +1,18 @@ +[Unit] +Description=VyOS Router +After=systemd-journald-dev-log.socket time-sync.target local-fs.target +Conflicts=shutdown.target +Before=systemd-user-sessions.service + +[Service] +Type=simple +Restart=no +TimeoutSec=5min +KillMode=process +RemainAfterExit=yes +ExecStart=/usr/libexec/vyos/init/vyos-router start +ExecStop=/usr/libexec/vyos/init/vyos-router stop +StandardOutput=journal+console + +[Install] +WantedBy=vyos.target diff --git a/debian/vyatta-cfg.vyos.target b/debian/vyatta-cfg.vyos.target new file mode 100644 index 0000000..47c91c1 --- /dev/null +++ b/debian/vyatta-cfg.vyos.target @@ -0,0 +1,3 @@ +[Unit] +Description=VyOS target +After=multi-user.target diff --git a/etc/init.d/vyatta-router b/etc/init.d/vyatta-router deleted file mode 100755 index c57387c..0000000 --- a/etc/init.d/vyatta-router +++ /dev/null @@ -1,250 +0,0 @@ -#!/bin/bash -### BEGIN INIT INFO -# Provides: vyatta-router -# Required-Start: $syslog $time $local_fs -# Required-Stop: $syslog $time $local_fs -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: VyOS Router -# Description: Debian init script for the VyOS Router -### END INIT INFO -# **** License **** -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# A copy of the GNU General Public License is available as -# `/usr/share/common-licenses/GPL' in the Debian GNU/Linux distribution -# or on the World Wide Web at `http://www.gnu.org/copyleft/gpl.html'. -# You can also obtain it by writing to the Free Software Foundation, -# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, -# MA 02110-1301, USA. -# -# Author: Tom Grennan -# **** End License **** - -. /lib/lsb/init-functions - -: ${vyatta_env:=/etc/default/vyatta} -source $vyatta_env - -declare progname=${0##*/} -declare action=$1; shift - -declare -x BOOTFILE=$vyatta_sysconfdir/config/config.boot - -# If vyos-config= boot option is present, use that file instead -VYOS_CONFIG=$(cat /proc/cmdline | grep -Eo '\bvyos-config=(\S+)\b' /proc/cmdline | awk -F'=' '{print $2}') - -if [ ! -z "$VYOS_CONFIG" ]; then - if [ -r "$VYOS_CONFIG" ]; then - echo "Config selected manually: $VYOS_CONFIG" - declare -x BOOTFILE="$VYOS_CONFIG" - else - echo "WARNING: Could not read selected config file, using default!" - fi -fi - -declare -a subinit -declare -a all_subinits=( - rl-system - firewall ) - -if [ $# -gt 0 ] ; then - for s in $@ ; do - [ -x ${vyatta_sbindir}/${s}.init ] && subinit[${#subinit}]=$s - done -else - for s in ${all_subinits[@]} ; do - [ -x ${vyatta_sbindir}/${s}.init ] && subinit[${#subinit}]=$s - done -fi - -GROUP=vyattacfg - -# check if bootup of this portion is disabled -disabled () { - grep -q -w no-vyos-$1 /proc/cmdline -} - -# if necessary, provide initial config -init_bootfile () { - if [ ! -r $BOOTFILE ] ; then - if [ -f $vyatta_sysconfdir/config.boot.default ]; then - cp $vyatta_sysconfdir/config.boot.default $BOOTFILE - else - $vyatta_sbindir/vyatta_current_conf_ver.pl > $BOOTFILE - fi - - chgrp ${GROUP} $BOOTFILE - chmod 660 $BOOTFILE - fi -} - -# if necessary, migrate initial config -migrate_bootfile () -{ - if [ -x $vyatta_sbindir/vyatta_config_migrate.pl ]; then - log_progress_msg migrate - sg ${GROUP} -c "$vyatta_sbindir/vyatta_config_migrate.pl $BOOTFILE" - fi -} - -# load the initial config -load_bootfile () -{ - log_progress_msg configure - ( - if [ -f /etc/default/vyatta-load-boot ]; then - # build-specific environment for boot-time config loading - source /etc/default/vyatta-load-boot - fi - sg ${GROUP} -c "$vyatta_sbindir/vyatta-boot-config-loader $BOOTFILE" - ) -} - -# execute the pre-config script -run_preconfig_script () -{ - if [ -x /config/scripts/vyos-preconfig-bootup.script ]; then - /config/scripts/vyos-preconfig-bootup.script - fi -} - -run_postupgrade_script () -{ - if [ -f /config/.upgraded ]; then - # Run the system script - /usr/libexec/vyos/system/post-upgrade - - # Run user scripts - if [ -d /config/scripts/post-upgrade.d ]; then - run-parts /config/scripts/post-upgrade.d - fi - - rm -f /config/.upgraded - fi -} - -# -# On image booted machines, we need to mount /boot from the image-specific -# boot directory so that kernel package installation will put the -# files in the right place. We also have to mount /boot/grub from the -# system-wide grub directory so that tools that edit the grub.cfg -# file will find it in the expected location. -# -bind_mount_boot () -{ - persist_path=$(/opt/vyatta/sbin/vyos-persistpath) - if [ $? == 0 ]; then - if [ -e $persist_path/boot ]; then - image_name=$(cat /proc/cmdline | sed -e s+^.*vyos-union=/boot/++ | sed -e 's/ .*$//') - - if [ -n "$image_name" ]; then - mount --bind $persist_path/boot/$image_name /boot - - if [ $? -ne 0 ]; then - echo "Couldn't bind mount /boot" - fi - - if [ ! -d /boot/grub ]; then - mkdir /boot/grub - fi - - mount --bind $persist_path/boot/grub /boot/grub - if [ $? -ne 0 ]; then - echo "Couldn't bind mount /boot/grub" - fi - fi - fi - fi -} - -start () -{ - # Fixup for FRR - - # In 5.1 master, zebra thinks existence of /var/run/netns is - # a requirement for netns support - mkdir /var/run/netns - - # Since systemd doesn't work without watchfrr and watchfrr restarts - # all daemons if just one failed, do the start manually - /usr/lib/frr/frr start - - log_action_begin_msg "Mounting VyOS Config" - # ensure the vyatta_configdir supports a large number of inodes since - # the config hierarchy is often inode-bound (instead of size). - # impose a minimum and then scale up dynamically with the actual size - # of the system memory. - local tmem=$(sed -n 's/^MemTotal: \+\([0-9]\+\) kB$/\1/p' /proc/meminfo) - local tpages - local tmpfs_opts="nosuid,nodev,mode=775,nr_inodes=0" #automatically allocate inodes - mount -o $tmpfs_opts -t tmpfs none ${vyatta_configdir} \ - && chgrp ${GROUP} ${vyatta_configdir} - log_action_end_msg $? - - disabled bootfile || init_bootfile - - log_daemon_msg "Starting VyOS router" - disabled migrate || migrate_bootfile - - run_preconfig_script - - run_postupgrade_script - - for s in ${subinit[@]} ; do - if ! disabled $s; then - log_progress_msg $s - if ! ${vyatta_sbindir}/${s}.init start - then log_failure_msg - exit 1 - fi - fi - done - - disabled configure || load_bootfile - log_end_msg $? - - telinit q - bind_mount_boot - chmod g-w,o-w / -} - -stop() -{ - local -i status=0 - log_daemon_msg "Stopping VyOS router" - for ((i=${#sub_inits[@]} - 1; i >= 0; i--)) ; do - s=${subinit[$i]} - log_progress_msg $s - ${vyatta_sbindir}/${s}.init stop - let status\|=$? - done - log_end_msg $status - log_action_begin_msg "Un-mounting VyOS Config" - umount ${vyatta_configdir} - log_action_end_msg $? - - /usr/lib/frr/frr stop -} - -case "$action" in - start) start ;; - stop) stop ;; - restart|force-reload) stop && start ;; - *) log_failure_msg "usage: $progname [ start|stop|restart ] [ subinit ... ]" ; - false ;; -esac - -exit $? - -# Local Variables: -# mode: shell-script -# sh-indentation: 4 -# End: diff --git a/etc/systemd/aftervyos.conf b/etc/systemd/aftervyos.conf new file mode 100644 index 0000000..c575390 --- /dev/null +++ b/etc/systemd/aftervyos.conf @@ -0,0 +1,3 @@ +[Service] +ExecStartPre=-/usr/libexec/vyos/init/vyos-config +StandardOutput=journal+console diff --git a/scripts/init/vyos-config b/scripts/init/vyos-config new file mode 100755 index 0000000..c3b826f --- /dev/null +++ b/scripts/init/vyos-config @@ -0,0 +1,18 @@ +#!/bin/bash + +while ps -ef | grep my_commit | grep -q -v grep; do + sleep 1 +done + +while [ ! -f /tmp/vyos-config-status ] +do + sleep 1 +done + +status=$(cat /tmp/vyos-config-status) + +if [ $status -ne 0 ]; then + echo "Configuration error" +else + echo "Configuration success" +fi diff --git a/scripts/init/vyos-router b/scripts/init/vyos-router new file mode 100755 index 0000000..078e118 --- /dev/null +++ b/scripts/init/vyos-router @@ -0,0 +1,244 @@ +#!/bin/bash +# **** License **** +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# A copy of the GNU General Public License is available as +# `/usr/share/common-licenses/GPL' in the Debian GNU/Linux distribution +# or on the World Wide Web at `http://www.gnu.org/copyleft/gpl.html'. +# You can also obtain it by writing to the Free Software Foundation, +# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +# MA 02110-1301, USA. +# +# Author: Tom Grennan +# **** End License **** + +. /lib/lsb/init-functions + +: ${vyatta_env:=/etc/default/vyatta} +source $vyatta_env + +declare progname=${0##*/} +declare action=$1; shift + +declare -x BOOTFILE=$vyatta_sysconfdir/config/config.boot + +# If vyos-config= boot option is present, use that file instead +for x in $(cat /proc/cmdline); do + [[ $x = vyos-config=* ]] || continue + VYOS_CONFIG="${x#vyos-config=}" +done + +if [ ! -z "$VYOS_CONFIG" ]; then + if [ -r "$VYOS_CONFIG" ]; then + echo "Config selected manually: $VYOS_CONFIG" + declare -x BOOTFILE="$VYOS_CONFIG" + else + echo "WARNING: Could not read selected config file, using default!" + fi +fi + +declare -a subinit +declare -a all_subinits=( + rl-system + firewall ) + +if [ $# -gt 0 ] ; then + for s in $@ ; do + [ -x ${vyatta_sbindir}/${s}.init ] && subinit[${#subinit}]=$s + done +else + for s in ${all_subinits[@]} ; do + [ -x ${vyatta_sbindir}/${s}.init ] && subinit[${#subinit}]=$s + done +fi + +GROUP=vyattacfg + +# check if bootup of this portion is disabled +disabled () { + grep -q -w no-vyos-$1 /proc/cmdline +} + +# if necessary, provide initial config +init_bootfile () { + if [ ! -r $BOOTFILE ] ; then + if [ -f $vyatta_sysconfdir/config.boot.default ]; then + cp $vyatta_sysconfdir/config.boot.default $BOOTFILE + else + $vyatta_sbindir/vyatta_current_conf_ver.pl > $BOOTFILE + fi + + chgrp ${GROUP} $BOOTFILE + chmod 660 $BOOTFILE + fi +} + +# if necessary, migrate initial config +migrate_bootfile () +{ + if [ -x $vyatta_sbindir/vyatta_config_migrate.pl ]; then + log_progress_msg migrate + sg ${GROUP} -c "$vyatta_sbindir/vyatta_config_migrate.pl $BOOTFILE" + fi +} + +# load the initial config +load_bootfile () +{ + log_progress_msg configure + ( + if [ -f /etc/default/vyatta-load-boot ]; then + # build-specific environment for boot-time config loading + source /etc/default/vyatta-load-boot + fi + sg ${GROUP} -c "$vyatta_sbindir/vyatta-boot-config-loader $BOOTFILE" + ) +} + +# execute the pre-config script +run_preconfig_script () +{ + if [ -x /config/scripts/vyos-preconfig-bootup.script ]; then + /config/scripts/vyos-preconfig-bootup.script + fi +} + +run_postupgrade_script () +{ + if [ -f /config/.upgraded ]; then + # Run the system script + /usr/libexec/vyos/system/post-upgrade + + # Run user scripts + if [ -d /config/scripts/post-upgrade.d ]; then + run-parts /config/scripts/post-upgrade.d + fi + + rm -f /config/.upgraded + fi +} + +# +# On image booted machines, we need to mount /boot from the image-specific +# boot directory so that kernel package installation will put the +# files in the right place. We also have to mount /boot/grub from the +# system-wide grub directory so that tools that edit the grub.cfg +# file will find it in the expected location. +# +bind_mount_boot () +{ + persist_path=$(/opt/vyatta/sbin/vyos-persistpath) + if [ $? == 0 ]; then + if [ -e $persist_path/boot ]; then + image_name=$(cat /proc/cmdline | sed -e s+^.*vyos-union=/boot/++ | sed -e 's/ .*$//') + + if [ -n "$image_name" ]; then + mount --bind $persist_path/boot/$image_name /boot + + if [ $? -ne 0 ]; then + echo "Couldn't bind mount /boot" + fi + + if [ ! -d /boot/grub ]; then + mkdir /boot/grub + fi + + mount --bind $persist_path/boot/grub /boot/grub + if [ $? -ne 0 ]; then + echo "Couldn't bind mount /boot/grub" + fi + fi + fi + fi +} + +start () +{ + # Fixup for FRR + + # In 5.1 master, zebra thinks existence of /var/run/netns is + # a requirement for netns support + mkdir -p /var/run/netns + + # Since systemd doesn't work without watchfrr and watchfrr restarts + # all daemons if just one failed, do the start manually + /usr/lib/frr/frr start + + log_action_begin_msg "Mounting VyOS Config" + # ensure the vyatta_configdir supports a large number of inodes since + # the config hierarchy is often inode-bound (instead of size). + # impose a minimum and then scale up dynamically with the actual size + # of the system memory. + local tmem=$(sed -n 's/^MemTotal: \+\([0-9]\+\) kB$/\1/p' /proc/meminfo) + local tpages + local tmpfs_opts="nosuid,nodev,mode=775,nr_inodes=0" #automatically allocate inodes + mount -o $tmpfs_opts -t tmpfs none ${vyatta_configdir} \ + && chgrp ${GROUP} ${vyatta_configdir} + log_action_end_msg $? + + disabled bootfile || init_bootfile + + log_daemon_msg "Starting VyOS router" + disabled migrate || migrate_bootfile + + run_preconfig_script + + run_postupgrade_script + + for s in ${subinit[@]} ; do + if ! disabled $s; then + log_progress_msg $s + if ! ${vyatta_sbindir}/${s}.init start + then log_failure_msg + exit 1 + fi + fi + done + + disabled configure || load_bootfile + log_end_msg $? + + telinit q + bind_mount_boot + chmod g-w,o-w / +} + +stop() +{ + local -i status=0 + log_daemon_msg "Stopping VyOS router" + for ((i=${#sub_inits[@]} - 1; i >= 0; i--)) ; do + s=${subinit[$i]} + log_progress_msg $s + ${vyatta_sbindir}/${s}.init stop + let status\|=$? + done + log_end_msg $status + log_action_begin_msg "Un-mounting VyOS Config" + umount ${vyatta_configdir} + log_action_end_msg $? + + /usr/lib/frr/frr stop +} + +case "$action" in + start) start ;; + stop) stop ;; + restart|force-reload) stop && start ;; + *) log_failure_msg "usage: $progname [ start|stop|restart ] [ subinit ... ]" ; + false ;; +esac + +exit $? + +# Local Variables: +# mode: shell-script +# sh-indentation: 4 +# End: diff --git a/scripts/system-generators/vyos-generator b/scripts/system-generators/vyos-generator new file mode 100755 index 0000000..34faab6 --- /dev/null +++ b/scripts/system-generators/vyos-generator @@ -0,0 +1,94 @@ +#!/bin/sh +set -f + +LOG="" +DEBUG_LEVEL=1 +LOG_D="/run/vyos-router" +ENABLE="enabled" +DISABLE="disabled" +FOUND="found" +NOTFOUND="notfound" +RUN_ENABLED_FILE="$LOG_D/$ENABLE" +VYOS_SYSTEM_TARGET="/lib/systemd/system/vyos.target" +VYOS_TARGET_NAME="vyos.target" + +debug() { + local lvl="$1" + shift + [ "$lvl" -gt "$DEBUG_LEVEL" ] && return + if [ -z "$LOG" ]; then + local log="$LOG_D/${0##*/}.log" + { [ -d "$LOG_D" ] || mkdir -p "$LOG_D"; } && + { : > "$log"; } >/dev/null 2>&1 && LOG="$log" || + LOG="/dev/kmsg" + fi + echo "$@" >> "$LOG" +} + +default() { + _RET="$ENABLE" +} + +main() { + local normal_d="$1" early_d="$2" late_d="$3" + local target_name="multi-user.target" gen_d="$early_d" + local link_path="$gen_d/${target_name}.wants/${VYOS_TARGET_NAME}" + local ds="$NOTFOUND" + + debug 1 "$0 normal=$normal_d early=$early_d late=$late_d" + debug 2 "$0 $*" + + local search result="error" ret="" + for search in default; do + if $search; then + debug 1 "$search found $_RET" + [ "$_RET" = "$ENABLE" -o "$_RET" = "$DISABLE" ] && + result=$_RET && break + else + ret=$? + debug 0 "search $search returned $ret" + fi + done + + # enable AND ds=found == enable + # enable AND ds=notfound == disable + # disable || == disabled + if [ "$result" = "$ENABLE" ]; then + if [ -e "$link_path" ]; then + debug 1 "already enabled: no change needed" + else + [ -d "${link_path%/*}" ] || mkdir -p "${link_path%/*}" || + debug 0 "failed to make dir $link_path" + if ln -snf "$VYOS_SYSTEM_TARGET" "$link_path"; then + debug 1 "enabled via $link_path -> $VYOS_SYSTEM_TARGET" + else + ret=$? + debug 0 "[$ret] enable failed:" \ + "ln $VYOS_SYSTEM_TARGET $link_path" + fi + fi + : > "$RUN_ENABLED_FILE" + elif [ "$result" = "$DISABLE" ]; then + if [ -f "$link_path" ]; then + if rm -f "$link_path"; then + debug 1 "disabled. removed existing $link_path" + else + ret=$? + debug 0 "[$ret] disable failed, remove $link_path" + fi + else + debug 1 "already disabled: no change needed [no $link_path]" + fi + if [ -e "$RUN_ENABLED_FILE" ]; then + rm -f "$RUN_ENABLED_FILE" + fi + else + debug 0 "unexpected result '$result' 'ds=$ds'" + ret=3 + fi + return $ret +} + +main "$@" + +# vi: ts=4 expandtab diff --git a/scripts/vyatta-boot-config-loader b/scripts/vyatta-boot-config-loader index d9c0903..f70d88c 100755 --- a/scripts/vyatta-boot-config-loader +++ b/scripts/vyatta-boot-config-loader @@ -48,11 +48,15 @@ umask 0002 # do commit trace '-- begin commit' ret=0 + echo $ret > /tmp/vyos-config-status + sync export COMMIT_VIA=boot-config-loader if ! do_commit ; then do_log err 'Commit failed at boot.' trace '-- commit failed' ret=1 + echo $ret > /tmp/vyos-config-status + sync else trace '-- commit succeeded' fi @@ -69,4 +73,3 @@ umask 0002 ) >$CLOG 2>&1 exit $? - -- cgit v1.2.3