diff options
author | Ales Kozumplik <akozumpl@redhat.com> | 2010-01-08 18:03:17 +0100 |
---|---|---|
committer | Ales Kozumplik <akozumpl@redhat.com> | 2010-01-21 11:31:55 +0100 |
commit | 9844c47bf9d2c61fe83f79de5d48c605f9e6780e (patch) | |
tree | 26c021280cdc4da12bb58eb08d8994966b1e6eb0 | |
parent | 86a61d49cbd2fa2731c730bc42297a42b0b561e6 (diff) | |
download | anaconda-9844c47bf9d2c61fe83f79de5d48c605f9e6780e.tar.gz anaconda-9844c47bf9d2c61fe83f79de5d48c605f9e6780e.tar.xz anaconda-9844c47bf9d2c61fe83f79de5d48c605f9e6780e.zip |
Introducing a proper syslog daemon allows us to remove the syslogd stub we have.
-rwxr-xr-x | anaconda | 1 | ||||
-rw-r--r-- | anaconda_log.py | 1 | ||||
-rw-r--r-- | backend.py | 7 | ||||
-rw-r--r-- | backend_log.py | 88 | ||||
-rwxr-xr-x | command-stubs/syslogd-stub | 34 | ||||
-rwxr-xr-x | scripts/upd-instroot | 1 | ||||
-rw-r--r-- | syslogd.py | 104 |
7 files changed, 93 insertions, 143 deletions
@@ -308,6 +308,7 @@ def setupLoggingFromOpts(opts): anaconda_log.setHandlersLevel(storage.storage_log.logger, level) if opts.syslog: + anaconda_log.logger.remote_syslog = opts.syslog if opts.syslog.find(":") != -1: (host, port) = opts.syslog.split(":") anaconda_log.logger.addSysLogHandler(log, host, port=int(port)) diff --git a/anaconda_log.py b/anaconda_log.py index a985aa465..934532367 100644 --- a/anaconda_log.py +++ b/anaconda_log.py @@ -63,6 +63,7 @@ class AnacondaSyslogHandler(SysLogHandler): class AnacondaLog: def __init__ (self, minLevel=DEFAULT_LEVEL): self.loglevel = logging.DEBUG + self.remote_syslog = None # Create the base of the logger hierarcy. self.logger = logging.getLogger("anaconda") self.logger.setLevel(logging.DEBUG) diff --git a/backend.py b/backend.py index e8e1c841d..c6e0726db 100644 --- a/backend.py +++ b/backend.py @@ -25,7 +25,7 @@ import shutil import iutil import os, sys import logging -from syslogd import syslog +import backend_log from constants import * import isys @@ -113,9 +113,8 @@ class AnacondaBackend: pass storage.writeEscrowPackets(anaconda) - sys.stdout.flush() - syslog.stop() + backend_log.log.stop() def doInstall(self, anaconda): log.warning("doInstall not implemented for backend!") @@ -145,7 +144,7 @@ class AnacondaBackend: shutil.rmtree (syslogname) except OSError: pass - syslog.start (instPath, syslogname) + backend_log.log.start(instPath, syslogname) if upgrade: self.modeText = _("Upgrading %s\n") diff --git a/backend_log.py b/backend_log.py new file mode 100644 index 000000000..fd11692c9 --- /dev/null +++ b/backend_log.py @@ -0,0 +1,88 @@ +# backend_log.py +# Logging infrastructure for Anaconda's backend. +# +# Copyright (C) 2009 Red Hat, Inc. +# +# This copyrighted material is made available to anyone wishing to use, +# modify, copy, or redistribute it subject to the terms and conditions of +# the GNU General Public License v.2, or (at your option) any later version. +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY expressed or implied, including the implied warranties of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. You should have received a copy of the +# GNU General Public License along with this program; if not, write to the +# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the +# source code or documentation are not subject to the GNU General Public +# License and may only be used or replicated with the express permission of +# Red Hat, Inc. +# +# Red Hat Author(s): Ales Kozumplik <akozumpl@redhat.com> +# + +import logging +import os +import signal + +import anaconda_log +import iutil + +SYSLOG_PATH = '/sbin/rsyslogd' +SYSLOG_PIDFILE = '/var/run/rsyslog_backend.pid' +SYSLOG_CFGFILE = '/etc/rsyslog_backend.conf' + +CFG_TEMPLATE = """ +$ModLoad imuxsock +$InputUnixListenSocketHostName sysimage +$AddUnixListenSocket %(socket)s ++sysimage +*.* %(logfile)s;RSYSLOG_TraditionalFileFormat +%(remote_syslog)s +""" + +global_log = logging.getLogger("anaconda") +class BackendSyslog: + def __init__(self): + pass + + def build_cfg(self, root, log): + socket = "%s/dev/log" % (root, ) + remote_syslog = '' + if anaconda_log.logger.remote_syslog: + remote_syslog = "*.* @@%s" % (anaconda_log.logger.remote_syslog, ) + + cfg = CFG_TEMPLATE % { + 'socket' : socket, + 'logfile' : log, + 'remote_syslog' : remote_syslog + } + with open(SYSLOG_CFGFILE, 'w') as cfg_file: + cfg_file.write(cfg) + + def start(self, root, log): + """ Start an rsyslogd instance dedicated for the sysimage. + + Other possibility would be to change configuration and SIGHUP the + existing instance, but it could lose some of its internal queues and + give us problems with remote logging. + """ + self.build_cfg(root, log) + args = ['-c', '4', + '-f', SYSLOG_CFGFILE, + '-i', str(SYSLOG_PIDFILE)] + status = iutil.execWithRedirect(SYSLOG_PATH, args) + if status == 0: + global_log.info("Backend logger started.") + else: + global_log.error("Unable to start backend logger") + + def stop(self): + try: + with open(SYSLOG_PIDFILE, 'r') as pidfile: + pid = int(pidfile.read()) + os.kill(pid, signal.SIGKILL) + except: + return + global_log.info("Backend logger stopped.") + +log = BackendSyslog() diff --git a/command-stubs/syslogd-stub b/command-stubs/syslogd-stub deleted file mode 100755 index 2f3af9278..000000000 --- a/command-stubs/syslogd-stub +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/python -# -# syslogd-stub -# -# Copyright (C) 2007 Red Hat, Inc. All rights reserved. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# 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. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# - -import sys -sys.path.append('/usr/lib/anaconda') - -def usage(): - sys.stderr.write("syslogd [root] [output file]") - -if __name__ == "__main__": - from syslogd import Syslogd - if len(sys.argv) != 3: - usage() - sys.exit(1) - root = sys.argv[1] - output = sys.argv[2] - syslog = Syslogd (root, open (output, "a")) diff --git a/scripts/upd-instroot b/scripts/upd-instroot index d4ebcc619..d914aaa70 100755 --- a/scripts/upd-instroot +++ b/scripts/upd-instroot @@ -1012,7 +1012,6 @@ cp $DEST/usr/lib/anaconda/losetup-stub $DEST/usr/bin/losetup cp $DEST/usr/lib/anaconda/list-harddrives-stub $DEST/usr/bin/list-harddrives cp $DEST/usr/lib/anaconda/loadkeys-stub $DEST/usr/bin/loadkeys cp $DEST/usr/lib/anaconda/mknod-stub $DEST/usr/bin/mknod -cp $DEST/usr/lib/anaconda/syslogd-stub $DEST/usr/bin/syslogd mv $DEST/usr/sbin/anaconda $DEST/usr/bin/anaconda mv $DEST/usr/lib/anaconda-runtime/lib* $DEST/usr/$LIBDIR 2>/dev/null diff --git a/syslogd.py b/syslogd.py deleted file mode 100644 index 38e47cba6..000000000 --- a/syslogd.py +++ /dev/null @@ -1,104 +0,0 @@ -# -# syslogd.py - a simple syslogd implementation and wrapper for launching it -# -# Copyright (C) 1999, 2000, 2001 Red Hat, Inc. All rights reserved. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# 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. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# -# Author(s): Erik Troan <ewt@redhat.com> -# - -import sys, os -import string -from socket import * -from select import select - -import logging -log = logging.getLogger("anaconda") - -class Syslogd: - def goSyslog(self, output, sockName): - sock = socket(AF_UNIX, SOCK_STREAM) - - try: - os.unlink(sockName) - except os.error: - pass - - sock.bind(sockName) - acceptedFds = [] - sock.listen(5) - - while (1): - list = acceptedFds + [ sock ] - list = select(list, [], [])[0] - try: - list.remove(sock) - (fd, remoteAddr) = sock.accept() - acceptedFds.append(fd) - except ValueError: - pass - - for fd in list: - msg = fd.recv(50) - msg = string.replace(msg, chr(0), "\n") - if (msg): - output.write(msg) - output.flush() - else: - acceptedFds.remove(fd) - fd.close() - - def __init__(self, root = "", output = sys.stdout, socket = "/dev/log"): - filename = root + socket - self.goSyslog(output, filename) - -class InstSyslog: - def __init__ (self): - self.pid = -1 - - def start (self, root, log): - # don't run in the "install from livecd" case - if not os.path.exists("/usr/bin/syslogd"): - return - self.pid = os.fork () - if not self.pid: - # look on PYTHONPATH first, so we use updated anaconda - path = "/usr/bin/syslogd" - if os.environ.has_key('PYTHONPATH'): - for f in string.split(os.environ['PYTHONPATH'], ":"): - if os.access (f+"/syslogd", os.X_OK): - path = f+"/syslogd" - break - - if os.path.exists(path): - os.execv (path, ("syslogd", root, log)) - - def stop(self): - if self.pid == -1: - log.warn("syslogd not running to kill!") - return - try: - os.kill (self.pid, 15) - except OSError as e: - log.error("killing syslogd failed: %s %s" %(e.errno, e.strerror)) - - try: - os.waitpid (self.pid, 0) - except OSError as e: - log.error("exception from waitpid in syslogd::stop: %s %s" % (e.errno, e.strerror)) - - self.pid = -1 - -syslog = InstSyslog() |