Changeset 373 for trunk


Ignore:
Timestamp:
06/13/07 15:38:52 (17 years ago)
Author:
bastiaans
Message:

jobmond/jobmond.py:

  • added syslog support with backwards compatible config
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/jobmond/jobmond.py

    r368 r373  
    2424import sys, getopt, ConfigParser
    2525import time, os, socket, string, re
    26 import xdrlib, socket
     26import xdrlib, socket, syslog
    2727import xml, xml.sax
    2828from xml.sax import saxutils, make_parser
     
    117117        global DEBUG_LEVEL, DAEMONIZE, BATCH_SERVER, BATCH_POLL_INTERVAL
    118118        global GMOND_CONF, DETECT_TIME_DIFFS, BATCH_HOST_TRANSLATE
    119         global BATCH_API, QUEUE, GMETRIC_TARGET
     119        global BATCH_API, QUEUE, GMETRIC_TARGET, USE_SYSLOG
     120        global SYSLOG_LEVEL, SYSLOG_FACILITY
    120121
    121122        DEBUG_LEVEL     = cfg.getint( 'DEFAULT', 'DEBUG_LEVEL' )
    122123
    123124        DAEMONIZE       = cfg.getboolean( 'DEFAULT', 'DAEMONIZE' )
     125
     126        try:
     127                USE_SYSLOG      = cfg.getboolean( 'DEFAULT', 'USE_SYSLOG' )
     128
     129        except ConfigParser.NoOptionError:
     130
     131                USE_SYSLOG      = True
     132
     133                debug_msg( 0, 'ERROR: no option USE_SYSLOG found: assuming yes' )
     134
     135        if USE_SYSLOG:
     136
     137                try:
     138                        SYSLOG_LEVEL    = cfg.getint( 'DEFAULT', 'SYSLOG_LEVEL' )
     139
     140                except ConfigParser.NoOptionError:
     141
     142                        debug_msg( 0, 'ERROR: no option SYSLOG_LEVEL found: assuming level 0' )
     143                        SYSLOG_LEVEL    = 0
     144
     145                try:
     146
     147                        SYSLOG_FACILITY = eval( 'syslog.LOG_' + cfg.get( 'DEFAULT', 'SYSLOG_FACILITY' ) )
     148
     149                except AttributeError, detail:
     150
     151                        SYSLOG_FACILITY = syslog.LOG_DAEMON
     152
     153                        debug_msg( 0, 'ERROR: no option SYSLOG_FACILITY found: assuming facility DAEMON' )
    124154
    125155        try:
     
    169199                        BATCH_API       = api_guess
    170200                else:
    171                         debug_msg( 0, "fatal error: BATCH_API not set and can't make guess" )
     201                        debug_msg( 0, "FATAL ERROR: BATCH_API not set and can't make guess" )
    172202                        sys.exit( 1 )
    173203
     
    190220                if not GMOND_CONF:
    191221
    192                         debug_msg( 0, "fatal error: GMETRIC_TARGET or GMOND_CONF both not set!" )
     222                        debug_msg( 0, "FATAL ERROR: GMETRIC_TARGET and GMOND_CONF both not set! Set at least one!" )
    193223                        sys.exit( 1 )
    194224                else:
    195225
    196                         debug_msg( 0, "error: GMETRIC_TARGET not set: internel Gmetric handling aborted. Failing back to DEPRECATED use of gmond.conf/gmetric binary. This will slow down jobmond significantly!" )
     226                        debug_msg( 0, "ERROR: GMETRIC_TARGET not set: internel Gmetric handling aborted. Failing back to DEPRECATED use of gmond.conf/gmetric binary. This will slow down jobmond significantly!" )
    197227
    198228        return True
     
    231261
    232262                        if not os.path.exists( gmond_file ):
    233                                 debug_msg( 0, 'fatal error: ' + gmond_file + ' does not exist' )
     263                                debug_msg( 0, 'FATAL ERROR: ' + gmond_file + ' does not exist' )
    234264                                sys.exit( 1 )
    235265
     
    930960        """Print msg if at or above current debug level"""
    931961
    932         if (DEBUG_LEVEL >= level):
    933                         sys.stderr.write( msg + '\n' )
     962        if (not DAEMONIZE and DEBUG_LEVEL >= level):
     963                sys.stderr.write( msg + '\n' )
     964
     965        if (DAEMONIZE and USE_SYSLOG and SYSLOG_LEVEL >= level):
     966                syslog.syslog( msg )
    934967
    935968def write_pidfile():
     
    950983
    951984        global PBSQuery, PBSError
     985        global SYSLOG_FACILITY, USE_SYSLOG, BATCH_API, DAEMONIZE
    952986
    953987        if not processArgs( sys.argv[1:] ):
     
    962996                except ImportError:
    963997
    964                         debug_msg( 0, "fatal error: BATCH_API set to 'pbs' but python module 'pbs_python' is not installed" )
     998                        debug_msg( 0, "FATAL ERROR: BATCH_API set to 'pbs' but python module 'pbs_python' is not installed" )
    965999                        sys.exit( 1 )
    9661000
     
    9691003        elif BATCH_API == 'sge':
    9701004
    971                 debug_msg( 0, "fatal error: BATCH_API 'sge' implementation is currently broken, check future releases" )
     1005                debug_msg( 0, "FATAL ERROR: BATCH_API 'sge' implementation is currently broken, check future releases" )
    9721006
    9731007                sys.exit( 1 )
     
    9761010
    9771011        else:
    978                 debug_msg( 0, "fatal error: unknown BATCH_API '" + BATCH_API + "' is not supported" )
     1012                debug_msg( 0, "FATAL ERROR: unknown BATCH_API '" + BATCH_API + "' is not supported" )
    9791013
    9801014                sys.exit( 1 )
     1015
     1016        if( DAEMONIZE and USE_SYSLOG ):
     1017
     1018                syslog.openlog( 'jobmond', syslog.LOG_NOWAIT, SYSLOG_FACILITY )
     1019
    9811020
    9821021        if DAEMONIZE:
Note: See TracChangeset for help on using the changeset viewer.