Welcome to little lamb

Code » anopa » commit 4619f1c

stage1/2: Change how the logging works..

author Olivier Brunel
2015-11-19 18:14:53 UTC
committer Olivier Brunel
2015-11-20 15:26:48 UTC
parent 3f25c6c159964dc33d13cc86986dadea2b7255e9

stage1/2: Change how the logging works..

..that is, instead of logging into /run/initramfs/boot.log in stage 1 & 2, and
using aa-mvlog to move said file to /var/log/boot at the end of stage 2, now
stage 1 & 2 (much like stage 3) log directly into /var/log/boot/current

As a special treat however, stage 1 will first check for a file
/run/initramfs/boot.log and import its content into /var/log/boot/current if
found.

That way everything from stage 1 is logged into persistent storage, and the
whole process is simpler.

(One can still e.g. have a service at the end of stage 0, after mounting
/root-fs, that will create an empty file named after the first tainstamp of
/boot.log and update the /root-fs/var/log/boot/current symlink to point to it,
to keep one log file per boot.)

doc/aa-stage1.pod +7 -3
doc/aa-stage2.pod +3 -7
src/scripts/aa-stage1 +7 -1
src/scripts/aa-stage2 +2 -12

diff --git a/doc/aa-stage1.pod b/doc/aa-stage1.pod
index b8aebfa..61a6237 100644
--- a/doc/aa-stage1.pod
+++ b/doc/aa-stage1.pod
@@ -11,9 +11,13 @@ B<aa-stage1>
 B<aa-stage1>(1) is an B<execline> script meant to be used as I<init> for the
 system.
 
-It loads the environment from I</etc/anopa/env> (via B<s6-envdir>), and will log
-messages into file I</run/initramfs/boot.log>, prefixing them with a TAI
-timestamp via B<s6-tai64n>.
+It loads the environment from I</etc/anopa/env> (via B<s6-envdir>), and first
+checks if a file I</run/initramfs/boot.log> exists, and if so imports its
+content into I</var/log/boot/current> (This is aimed to import log messages from
+the initramfs, as e.g. B<aa-stage0>(1) generates them.)
+
+It will log its own messages into file I</var/log/boot/current>, prefixing them
+with a TAI timestamp via B<s6-tai64n>.
 
 It doesn't do much in itself, the bulk of the work being done via services. It
 will create the runtime repository I</run/services> using B<aa-enable>(1) and
diff --git a/doc/aa-stage2.pod b/doc/aa-stage2.pod
index 2aff53a..d57643a 100644
--- a/doc/aa-stage2.pod
+++ b/doc/aa-stage2.pod
@@ -12,7 +12,7 @@ B<aa-stage2>(1) is an B<execline> script called by B<aa-stage1> once the runtime
 repository has been created and B<s6-svscan> is running as PID 1, to actually
 perform all initialization tasks.
 
-It will log messages into file I</run/initramfs/boot.log>, prefixing them with a
+It will log messages into file I</var/log/boot/current>, prefixing them with a
 TAI timestamp via B<s6-tai64n>.
 
 It starts all services via B<aa-start>(1) using I</etc/anopa/listdirs/onboot> as
@@ -20,9 +20,5 @@ listdir, unless argument B<aa> was specified on kernel command line, in which
 case I</etc/anopa/listdirs/ARGVALUE> is used as listdir intead.
 
 If B<aa-start>(1) exits non-zero, it assumes there might not even be a getty
-running, and will try to open a shell (I<sh -i>).
-
-If B<aa-start>(1) exit zero, the system is assumed to be ready, and the log file
-I</run/initramfs/boot.log> will be moved to persistent storage, into
-I</var/log/boot>, via B<aa-mvlog>(1). If that fails, a warning will be shown
-(and added to the log file).
+running, and will try to open a shell (I<sh -i>). Else, the system is assumed to
+be ready.
diff --git a/src/scripts/aa-stage1 b/src/scripts/aa-stage1
index 1ab5eb5..da77788 100755
--- a/src/scripts/aa-stage1
+++ b/src/scripts/aa-stage1
@@ -23,12 +23,18 @@
 
 @BINDIR@/emptyenv @BINDIR@/s6-envdir /etc/anopa/env @BINDIR@/exec
 
+# Import log messages from initramfs, if possible
+foreground {
+    if -X { aa-test -f /run/initramfs/boot.log }
+    redirfd -a 1 /var/log/boot/current cat /run/initramfs/boot.log
+}
+
 # Set up a pipe to log messages
 piperw 3 4
 background
 {
     fdclose 4 fdmove 0 3
-    redirfd -a 1 /run/initramfs/boot.log
+    redirfd -a 1 /var/log/boot/current
     fdmove -c 2 1
     s6-tai64n
 }
diff --git a/src/scripts/aa-stage2 b/src/scripts/aa-stage2
index 4b2ac3d..2fa34aa 100755
--- a/src/scripts/aa-stage2
+++ b/src/scripts/aa-stage2
@@ -26,7 +26,7 @@ piperw 3 4
 background
 {
   fdclose 4 fdmove 0 3
-  redirfd -a 1 /run/initramfs/boot.log
+  redirfd -a 1 /var/log/boot/current
   fdmove -c 2 1
   s6-tai64n
 }
@@ -49,17 +49,7 @@ if -n -t
   # 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} }
-  foreground { aa-echo -DB "System ready." }
-  # close logger
-  fdmove -c 2 1
-  # no more input
-  redirfd -r 0 /dev/null
-  # move log to file system
-  if -n -t { aa-mvlog /run/initramfs/boot.log /var/log/boot }
-  # show (& log) a warning
-  pipeline { aa-echo -DBw "Failed to save /run/initramfs/boot.log to /var/log/boot" }
-  redirfd -a 1 /run/initramfs/boot.log
-  s6-tai64n
+  aa-echo -DB "System ready."
 }
 
 # Something went wrong, likely aa-start failed (i.e. an essential service failed