def trace(self, txt):
        """
        Display message in the screen

        @param txt: message
        @type txt: string
        """
        Logger.debug("[%s] %s" %
                     (self.__class__.__name__, unicode(txt).encode('utf-8')))
Example #2
0
    def trace(self, txt):
        """
        Display message in the screen

        @param txt: message
        @type txt: string
        """
        if sys.version_info[0] < 3:
            if not isinstance(txt, unicode):
                txt = unicode(txt, 'latin2')
        Logger.debug("[%s] %s" % (self.__class__.__name__, txt))
Example #3
0
    def isUp(self):
        """
        Try to connect to the database
        Detect the version of the mysql server
        """

        timeoutVal = Settings.getInt('Boot', 'timeout-sql-server')

        timeout = False
        go = False
        startTime = time.time()
        while (not go) and (not timeout):
            # timeout elapsed ?
            if (time.time() - startTime) >= timeoutVal:
                timeout = True
            else:
                try:
                    self.trace("try to connect to the database")
                    conn = MySQLdb.connect(host=Settings.get('MySql', 'ip'),
                                           user=Settings.get('MySql', 'user'),
                                           passwd=Settings.get('MySql', 'pwd'),
                                           db=Settings.get('MySql', 'db'),
                                           unix_socket=Settings.get(
                                               'MySql', 'sock'))
                    go = True
                    self.trace("connection successful")
                except MySQLdb.Error as e:
                    Logger.debug("connect to the database failed: %s" % str(e))
                    Logger.debug("retry in %s second" %
                                 Settings.get('MySql', 'retry-connect'))
                    time.sleep(int(Settings.get('MySql', 'retry-connect')))

        if timeout:
            raise Exception("db manager not ready: timeout")

        if go:
            self.trace("retrieve mysql version")
            cursor = conn.cursor()
            cursor.execute("SELECT VERSION()")
            row = cursor.fetchone()
            cursor.close()
            conn.close()
            self.dbVersion = row[0]
            self.trace(self.dbVersion)
Example #4
0
def isUp():
    """
    Check if the web server if ready (apache)
    """
    try:
        # init the http 
        timeoutVal = Settings.getInt('Boot','timeout-http-server')
        http = httplib2.Http(timeout=timeoutVal, disable_ssl_certificate_validation=True, 
                            ca_certs="%s/Libs/cacerts.txt" % Settings.getDirExec() )
        http.add_credentials( Settings.get('Web','login'), Settings.get('Web','password') )
        http.force_exception_to_status_code = True
        scheme = 'http'
        portHttp = Settings.get('Web','http-port')
        if Settings.getInt('Web','https'):
            scheme = 'https'
            portHttp = Settings.get('Web','https-port')
        uri = '%s://%s:%s/%s/index.php' % ( scheme, 
                                            Settings.get('Web','fqdn'), 
                                            portHttp, 
                                            Settings.get('Web', 'path') )
        
        timeout = False
        go = False
        startTime = time.time()
        while (not go) and (not timeout):
            # timeout elapsed ?
            if (time.time() - startTime) >= timeoutVal:
                timeout = True
            else:
                # test the web server
                Logger.debug("Get index: %s" % uri)
                resp, content = http.request(uri, "GET")
                if resp['status'] == '200':
                    Logger.debug( "200 OK received" )
                    go = True
                else:
                    Logger.debug( "response incorrect (%s)" % resp['status'] )
                    Logger.debug( "response (%s)" % resp )
                    Logger.debug( "response content (%s)" % content )
                    Logger.debug( "retry in %s second" % Settings.get('Web','retry-connect') )
                    time.sleep( int(Settings.get('Web','retry-connect')) )
        
        if timeout:
            raise Exception("timeout" )
            
    except Exception as e:
        raise Exception("server web not ready: %s" % str(e) )