Re: [master] Introducing a proper syslog daemon allows us to remove the syslogd stub we have.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Code looks OK to me.

Just one thing, shouldn't we use execWithRedirect instead of commands.getstatusoutput to log the stdout/err of executed command too?

Martin

----- "Ales Kozumplik" <akozumpl@xxxxxxxxxx> wrote:

> ---
>  anaconda                   |    1 +
>  anaconda_log.py            |    1 +
>  backend.py                 |    7 +--
>  backend_log.py             |   91
> ++++++++++++++++++++++++++++++++++++++
>  command-stubs/syslogd-stub |   34 --------------
>  scripts/upd-instroot       |    1 -
>  syslogd.py                 |  104
> --------------------------------------------
>  7 files changed, 96 insertions(+), 143 deletions(-)
>  create mode 100644 backend_log.py
>  delete mode 100755 command-stubs/syslogd-stub
>  delete mode 100644 syslogd.py
> 
> diff --git a/anaconda b/anaconda
> index 78e5fd1..a210b52 100755
> --- a/anaconda
> +++ b/anaconda
> @@ -306,6 +306,7 @@ def setupLoggingFromOpts(opts):
>          storage.storage_log.logger.setHandlersLevel(level)
>  
>      if opts.syslog:
> +        logger.remote_syslog = opts.syslog
>          if opts.syslog.find(":") != -1:
>              (host, port) = opts.syslog.split(":")
>              logger.addSysLogHandler(log, host, port=int(port))
> diff --git a/anaconda_log.py b/anaconda_log.py
> index 3be4e6a..817bfb6 100644
> --- a/anaconda_log.py
> +++ b/anaconda_log.py
> @@ -55,6 +55,7 @@ class LoggerClass(logging.Logger):
>  
>  class AnacondaLog:
>      def __init__ (self, minLevel=DEFAULT_LEVEL):
> +        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 5ddeb8c..cdccc78 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
> @@ -105,9 +105,8 @@ class AnacondaBackend:
>              shutil.copytree(d, "/root/" + os.path.basename(d))
>  
>          storage.writeEscrowPackets(anaconda)
> -
>          sys.stdout.flush()
> -        syslog.stop()
> +        backend_log.log.stop()
>  
>      def doInstall(self, anaconda):
>          log.warning("doInstall not implemented for backend!")
> @@ -137,7 +136,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 0000000..fa4655e
> --- /dev/null
> +++ b/backend_log.py
> @@ -0,0 +1,91 @@
> +# 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@xxxxxxxxxx>
> +#
> +
> +import commands
> +import logging
> +import os
> +import signal
> +
> +import anaconda_log
> +
> +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)
> +        cmd = "%(syslog)s -c 4 -f %(cfg_file)s -i %(pid)s" % {
> +            'syslog'   : SYSLOG_PATH,
> +            'cfg_file' : SYSLOG_CFGFILE,
> +            'pid'      : SYSLOG_PIDFILE
> +            }
> +        global_log.debug("Backend log command: %s" % (cmd, ))
> +        (status, output) = commands.getstatusoutput(cmd)
> +        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 2f3af92..0000000
> --- 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 551bd11..e111c58 100755
> --- a/scripts/upd-instroot
> +++ b/scripts/upd-instroot
> @@ -996,7 +996,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 267b7fd..0000000
> --- 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@xxxxxxxxxx>
> -#
> -
> -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()
> -- 
> 1.6.2.5
> 
> _______________________________________________
> Anaconda-devel-list mailing list
> Anaconda-devel-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/anaconda-devel-list

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux