Saving the journal is a good idea - it has some log info that aren't in
our existing logs (dracut output, for example).
We could just make a copy of it at the end of the install, but we can
also make journald move its logs to disk by creating /var/log/journal
and sending it SIGUSR1.
Doing it this way rather than copying it at the end saves some RAM and
gives us on-disk logs that will be there even if you yank the power cord
before we get to kickstart %post.
So as soon as we're sure we've got somewhere persistent we can write to,
we should move the journal.
At the moment where preInstall happens we have the target disk mounted
but there's nothing on it yet. This seems it's probably the earliest
point where we can safely start writing to disk, so go ahead and do
that.
Oh - and make sure 99-copy-logs.ks doesn't chmod the journal dir 0600.
(and make it use $ANA_INSTALL_PATH consistently, while we're at it)
---
data/post-scripts/99-copy-logs.ks | 21 +++++++++++----------
pyanaconda/iutil.py | 29 +++++++++++++++++++++++++++++
pyanaconda/packaging/__init__.py | 1 +
3 files changed, 41 insertions(+), 10 deletions(-)
diff --git a/data/post-scripts/99-copy-logs.ks b/data/post-scripts/99-copy-logs.ks
index 1a60756..73e3c9c 100644
--- a/data/post-scripts/99-copy-logs.ks
+++ b/data/post-scripts/99-copy-logs.ks
@@ -1,16 +1,17 @@
# Note, this script log will not be copied to the installed system.
%post --nochroot
+LOGDIR=$ANA_INSTALL_PATH/var/log/anaconda
mkdir -p /mnt/sysimage/var/log/anaconda
-[ -e /tmp/anaconda.log ] && cp /tmp/anaconda.log
$ANA_INSTALL_PATH/var/log/anaconda/anaconda.log
-[ -e /tmp/syslog ] && cp /tmp/syslog $ANA_INSTALL_PATH/var/log/anaconda/syslog
-[ -e /tmp/X.log ] && cp /tmp/X.log
$ANA_INSTALL_PATH/var/log/anaconda/anaconda.xlog
-[ -e /tmp/program.log ] && cp /tmp/program.log
$ANA_INSTALL_PATH/var/log/anaconda/anaconda.program.log
-[ -e /tmp/packaging.log ] && cp /tmp/packaging.log
$ANA_INSTALL_PATH/var/log/anaconda/anaconda.packaging.log
-[ -e /tmp/storage.log ] && cp /tmp/storage.log
$ANA_INSTALL_PATH/var/log/anaconda/anaconda.storage.log
-[ -e /tmp/ifcfg.log ] && cp /tmp/ifcfg.log
$ANA_INSTALL_PATH/var/log/anaconda/anaconda.ifcfg.log
-[ -e /tmp/yum.log ] && cp /tmp/yum.log
$ANA_INSTALL_PATH/var/log/anaconda/anaconda.yum.log
-cp /tmp/ks-script*.log $ANA_INSTALL_PATH/var/log/anaconda/
-chmod 0600 /mnt/sysimage/var/log/anaconda/*
+[ -e /tmp/anaconda.log ] && cp /tmp/anaconda.log $LOGDIR/anaconda.log
+[ -e /tmp/syslog ] && cp /tmp/syslog $LOGDIR/syslog
+[ -e /tmp/X.log ] && cp /tmp/X.log $LOGDIR/anaconda.xlog
+[ -e /tmp/program.log ] && cp /tmp/program.log $LOGDIR/anaconda.program.log
+[ -e /tmp/packaging.log ] && cp /tmp/packaging.log
$LOGDIR/anaconda.packaging.log
+[ -e /tmp/storage.log ] && cp /tmp/storage.log $LOGDIR/anaconda.storage.log
+[ -e /tmp/ifcfg.log ] && cp /tmp/ifcfg.log $LOGDIR/anaconda.ifcfg.log
+[ -e /tmp/yum.log ] && cp /tmp/yum.log $LOGDIR/anaconda.yum.log
+cp /tmp/ks-script*.log $LOGDIR/
+chmod 0600 $LOGDIR/{syslog,*.log}
%end
diff --git a/pyanaconda/iutil.py b/pyanaconda/iutil.py
index 05e7753..bcb1934 100644
--- a/pyanaconda/iutil.py
+++ b/pyanaconda/iutil.py
@@ -480,3 +480,32 @@ class ProxyString(object):
def __str__(self):
return self.url
+def pidof(procname):
+ def cmdmatch(pid):
+ try:
+ argv =
open("/proc/"+pid+"/cmdline").read().split('\0')
+ except IOError:
+ return False
+ return procname in (argv[0], os.path.basename(argv[0]))
+ return [int(pid) for p in os.listdir("/proc") if cmdmatch(p)]
+
+def killall(name, sig=signal.SIGTERM):
+ killed = []
+ for pid in pidof(name):
+ if pid == os.getpid():
+ continue
+ try:
+ os.kill(sig, pid)
+ killed.append(pid)
+ except IOError: # e.g. ESRCH ('No such process')
+ pass
+ return killed
+
+def move_journal_to_disk():
+ targetdir = ROOT_PATH+"/var/log/anaconda/journal"
+ log.info("moving journal to", targetdir)
+ mkdirChain(targetdir)
+ os.symlink(targetdir, "/var/log/journal")
+ for name in ("systemd-journald", "journald"):
+ for pid in killall(name, signal.SIGUSR1):
+ log.info("sent SIGUSR1 to %s (pid %s)", name, pid)
diff --git a/pyanaconda/packaging/__init__.py b/pyanaconda/packaging/__init__.py
index cba0f79..961a819 100644
--- a/pyanaconda/packaging/__init__.py
+++ b/pyanaconda/packaging/__init__.py
@@ -487,6 +487,7 @@ class Payload(object):
def preInstall(self, packages=None, groups=None):
""" Perform pre-installation tasks. """
iutil.mkdirChain(ROOT_PATH + "/root")
+ iutil.move_journal_to_disk()
def install(self):
""" Install the payload. """
--
1.8.1.4