author | Olivier Brunel
<jjk@jjacky.com> 2018-01-20 12:05:15 UTC |
committer | Olivier Brunel
<jjk@jjacky.com> 2018-01-21 19:49:03 UTC |
parent | 9d11a74250c019ccbe3da0c9783f2a292868843d |
src/scripts/aa-stage0 | +13 | -15 |
src/scripts/aa-stage1 | +12 | -11 |
src/scripts/aa-stage2 | +10 | -9 |
src/scripts/aa-stage3 | +19 | -25 |
diff --git a/src/scripts/aa-stage0 b/src/scripts/aa-stage0 index b4323de..94e71a1 100755 --- a/src/scripts/aa-stage0 +++ b/src/scripts/aa-stage0 @@ -3,7 +3,7 @@ # anopa - Copyright (C) 2015-2017 Olivier Brunel # # aa-stage0 -# Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> +# Copyright (C) 2015-2018 Olivier Brunel <jjk@jjacky.com> # # This file is part of anopa. # @@ -33,10 +33,10 @@ background s6-tai64n } -# aa-* tools will send output to both 1 & 2 via -D +# aa-* tools will duplicate their output to 3 via -O3 fdclose 3 -fdmove 2 4 -foreground { aa-echo -D "Stage 0: Mounting root file system..." } +fdmove 3 4 +foreground { aa-echo -O3 "Stage 0: Mounting root file system..." } # Safety cd / @@ -45,32 +45,30 @@ umask 022 # Start services foreground { if -n { - if { emptyenv -c s6-setsid aa-ctty -Ds aa-start -D -r /services -l onboot } + if { emptyenv -c s6-setsid aa-ctty -O3 -s aa-start -O3 -r /services -l onboot } foreground { # if "break" was specified on kernel cmdline, let's open a shell - if -t { aa-incmdline -Dqf /root-fs/proc/cmdline break } - foreground { aa-echo -DB "Break requested" } - foreground { aa-echo -Dt "Trying to open a shell; " +g exit +w " to continue" } - fdmove -c 2 1 + if -t { aa-incmdline -O3 -qf /root-fs/proc/cmdline break } + foreground { aa-echo -O3 -B "Break requested" } + foreground { aa-echo -O3 -t "Trying to open a shell; " +g exit +w " to continue" } emptyenv -c sh -i } } # aa-start failed (i.e. an essential service failed to be started), so we assume # the root fs wasn't mounted: try a shell so user has a chance to fix things -foreground { aa-echo -DBe "Mouting root file system failed" } -foreground { aa-echo -Dt "Trying to open a shell; " +g exit +w " to continue" } -fdmove -c 2 1 +foreground { aa-echo -O3 -Be "Mouting root file system failed" } +foreground { aa-echo -O3 -t "Trying to open a shell; " +g exit +w " to continue" } emptyenv -c sh -i } -if { aa-echo -DB "Moving /root-fs to /..." } +if { aa-echo -O3 -B "Moving /root-fs to /..." } # First we mount bind the rootfs (initramfs) onto /run/initramfs so we can come # back to it for stage 4 -if { aa-mount -DBd / /root-fs/run/initramfs } -fdmove -c 2 1 +if { aa-mount -O3 -Bd / /root-fs/run/initramfs } backtick -n -D /sbin/init INIT { aa-incmdline -rf /root-fs/proc/cmdline init } importas -u INIT INIT +fdclose 3 cd /root-fs if { aa-mount -M . / } ./run/initramfs/bin/emptyenv -c ./run/initramfs/bin/aa-chroot . ${INIT} diff --git a/src/scripts/aa-stage1 b/src/scripts/aa-stage1 index 8d51898..f01b91e 100755 --- a/src/scripts/aa-stage1 +++ b/src/scripts/aa-stage1 @@ -39,32 +39,31 @@ background s6-tai64n } -# aa-* tools will send output to both 1 & 2 via -D +# aa-* tools will duplicate their output to 3 via -O3 fdclose 3 -fdmove 2 4 -foreground { aa-echo -DB "Stage 1: Preparing system..." } +fdmove 3 4 +foreground { aa-echo -O3 -B "Stage 1: Preparing system..." } # Safety cd / umask 022 # Create the repository -backtick -n -D onboot REPODIR { aa-incmdline -Drs aa } +backtick -n -D onboot REPODIR { aa-incmdline -O3 -rs aa } backtick -n -D onboot REPODIR { importas -u REPODIR REPODIR if { aa-test -e /var/lib/repodir/$REPODIR } echo $REPODIR } importas -u REPODIR REPODIR -foreground { aa-echo -Dt "Copying ${REPODIR} repodir as /run/services..." } -foreground { emptyenv -c aa-hiercopy -D /var/lib/repodir/$REPODIR /run/services } +foreground { aa-echo -O3 -t "Copying ${REPODIR} repodir as /run/services..." } +foreground { emptyenv -c aa-hiercopy -O3 /var/lib/repodir/$REPODIR /run/services } -foreground { aa-echo -Dt "Starting s6-svscan..." } +foreground { aa-echo -O3 -t "Starting s6-svscan..." } # Make sure the FIFO needed for the switch to stage 2 is there -ifelse -X -n { aa-test -Dp /run/services/.scandir/uncaught-logs/fifo } +ifelse -X -n { aa-test -O3 -p /run/services/.scandir/uncaught-logs/fifo } { - foreground { aa-echo -DBe "Cannot start s6-svscan: No uncaught-logs fifo found" } - fdmove -c 2 1 - foreground { aa-echo -t "Trying to open a shell..." } + foreground { aa-echo -O3 -Be "Cannot start s6-svscan: No uncaught-logs fifo found" } + foreground { aa-echo -O3 -t "Trying to open a shell..." } emptyenv -c sh -i } @@ -72,6 +71,8 @@ ifelse -X -n { aa-test -Dp /run/services/.scandir/uncaught-logs/fifo } redirfd -r 0 /dev/null redirfd -wnb 1 /run/services/uncaught-logs/fifo # (black magic: doesn't block) fdmove -c 2 1 +# close logger +fdclose 3 # Fork the stage2 script and have it ready to start as soon as the catch-all # logger is in place diff --git a/src/scripts/aa-stage2 b/src/scripts/aa-stage2 index c139199..9aafe12 100755 --- a/src/scripts/aa-stage2 +++ b/src/scripts/aa-stage2 @@ -3,7 +3,7 @@ # anopa - Copyright (C) 2015-2017 Olivier Brunel # # aa-stage2 -# Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> +# Copyright (C) 2015-2018 Olivier Brunel <jjk@jjacky.com> # # This file is part of anopa. # @@ -31,7 +31,7 @@ background s6-tai64n } fdclose 3 -fdmove 2 4 +fdmove 3 4 if -n -t { @@ -39,17 +39,18 @@ if -n -t backtick -n TTY { aa-tty } importas -u TTY TTY redirfd -r 0 ${TTY} - # Reopen the console for stdout + # Reopen the console redirfd -w 1 /dev/console + fdmove -c 2 1 # And start everything - foreground { aa-echo -DB "Stage 2: Initializing system..." } - backtick -n -D onboot LISTDIR { aa-incmdline -Drs aa } + foreground { aa-echo -O3 -B "Stage 2: Initializing system..." } + backtick -n -D onboot LISTDIR { aa-incmdline -O3 -rs aa } importas -u LISTDIR LISTDIR # We have a tty in stdin, become session leader and set controlling terminal. # This is so Ctrl+C will trigger a SIGINT to aa-start, so one can manually # timeout a service. - if { emptyenv -c s6-setsid aa-ctty -D aa-start -D -l /etc/anopa/listdirs/${LISTDIR} } - aa-echo -DB "System ready." + if { emptyenv -c s6-setsid aa-ctty -O3 aa-start -O3 -l /etc/anopa/listdirs/${LISTDIR} } + aa-echo -O3 -B "System ready." } # Something went wrong, likely aa-start failed (i.e. an essential service failed @@ -57,7 +58,7 @@ if -n -t # has a chance to fix things redirfd -r 0 /dev/console redirfd -w 1 /dev/console -foreground { aa-echo -DBe "System initialization failed" } fdmove -c 2 1 -foreground { aa-echo -t "Trying to open a shell..." } +foreground { aa-echo -O3 -Be "System initialization failed" } +foreground { aa-echo -O3 -t "Trying to open a shell..." } emptyenv -c sh -i diff --git a/src/scripts/aa-stage3 b/src/scripts/aa-stage3 index d1a1390..f6e15b3 100755 --- a/src/scripts/aa-stage3 +++ b/src/scripts/aa-stage3 @@ -3,7 +3,7 @@ # anopa - Copyright (C) 2015-2017 Olivier Brunel # # aa-stage3 -# Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> +# Copyright (C) 2015-2018 Olivier Brunel <jjk@jjacky.com> # # This file is part of anopa. # @@ -28,10 +28,12 @@ background fdclose 4 fdmove 0 3 redirfd -a 1 /var/log/boot/current fdmove -c 2 1 + # put a @ as first char in argv[0] so it is skipped by the aa-kill calls + exec -a @logger s6-tai64n } fdclose 3 -fdmove 2 4 +fdmove 3 4 # Make sure we're sane cd / @@ -39,34 +41,27 @@ backtick -n TTY { aa-tty } importas -u TTY TTY redirfd -r 0 ${TTY} redirfd -w 1 /dev/console +fdmove -c 2 1 -foreground { aa-echo -DB "Stage 3: Preparing ${1}..." } +foreground { aa-echo -O3 -B "Stage 3: Preparing ${1}..." } # Stop all running services -- s6-svscan did only exec into us, leaving the # whole supervised tree intact. Here we stop everything (longrun & oneshot) in # order, save for the catch-all (it will get an 'x' though). -foreground { emptyenv -c s6-setsid aa-ctty -Ds aa-stop -D -aak uncaught-logs -t20 } +foreground { emptyenv -c s6-setsid aa-ctty -O3 -s aa-stop -O3 -aak uncaught-logs -t20 } # Now stop the catch-all logger (its supervisor will then exit) -foreground { emptyenv -c s6-setsid aa-stop -D uncaught-logs } +foreground { emptyenv -c s6-setsid aa-stop -O3 uncaught-logs } # Kill everything left -foreground { aa-echo -DB "Killing remaining processes..." } -foreground { aa-echo -Dt "Sending SIGTERM to all processes..." } -foreground { aa-kill -Dst } +foreground { aa-echo -O3 -B "Killing remaining processes..." } +foreground { aa-echo -O3 -t "Sending SIGTERM to all processes..." } +foreground { aa-kill -O3 -st } wait -t 4200 { } # Reap zombies -# logger was killed, and we won't open it back -fdmove -c 2 1 -foreground { pipeline { aa-echo -Dt "Sending SIGKILL to all processes..." } - redirfd -a 1 /var/log/boot/current - s6-tai64n -} -foreground { aa-kill -sk } +foreground { aa-echo -O3 -t "Sending SIGKILL to all processes..." } +foreground { aa-kill -O3 -sk } wait -t 2300 { } # Wait for all children foreground { aa-sync } -foreground { pipeline { aa-echo -DB "Pivoting root..." } - redirfd -a 1 /var/log/boot/current - s6-tai64n -} +foreground { aa-echo -O3 -B "Pivoting root..." } cd /run/initramfs foreground { @@ -75,16 +70,15 @@ foreground { # grab the chroot binary for after the pivot if { cp /bin/aa-chroot . } # PIVOT! - if { aa-pivot . root-fs } + if { aa-pivot -O3 . root-fs } } # Something went wrong - foreground { pipeline { aa-echo -DBe "Unable to ${1}: Failed to pivot root" } - redirfd -a 1 /var/log/boot/current - s6-tai64n - } - foreground { aa-echo -t "Trying to open a shell..." } + foreground { aa-echo -O3 -Be "Unable to ${1}: Failed to pivot root" } + foreground { aa-echo -O3 -t "Trying to open a shell..." } emptyenv -c sh -i } +# close the logger now +fdclose 3 # And let initramfs end things ($1 is halt/reboot/poweroff) ./aa-chroot . /shutdown ${1}