def main( argv=None ): if argv is None: argv = sys.argv try: try: opts, args = getopt.getopt( argv[1:], "dC:c:h", [ "debug", "config", "crontab", "help" ] ) except getopt.error, msg: raise Utils.Usage( msg ) debugMode = configFile = crontabFile = None for cliOpts, cliArgs in opts: if cliOpts in ( "-c", "--crontab" ): crontabFile = cliArgs if cliOpts in ( "-d", "--debug" ): debugMode = True if cliOpts in ( "-C", "--config" ): configFile = cliArgs if cliOpts in ( "-h", "--help" ): DisplayUsage() return 2 if not Platform.isRunning(): Utils.initLogging( logLevelNo=3 ) logFacility = logging.getLogger( Utils.returnScriptName( ) ) if configFile is None: print "A Config File Is Required." return 2 configSettings = Utils.loadConfig( configFile ) if not debugMode: if not Utils.makeDaemon(): logFacility.error( "Failed To Daemonize. Running In The Foreground. " ) print "Failed To Daemonize. Going To Run In The Foreground." if crontabFile is None: if not configSettings is None: cronDaemon = CronLib.CronSQL( configSettings ) else: print "There Was A Problem Loading The Config File. Check The Log File." return 2 else: try: cronDaemon = CronLib.CronFile( crontabFile ) except CronLib.CronError, errorMsg: logFacility.error( "Failed To Start crond. Reason: %s \n" % errorMsg ) print "Failed To Start crond. Reason: %s \n" % errorMsg return 1 cronDaemon.run()