コード例 #1
0
    def configure(self):
        
        #--------------------------------------------------------
        # Installs the Security Utilities
        #--------------------------------------------------------
        
        if os.system("python %s/glite-security-utils-config.py --subservice" % glib.getScriptPath()):
            print "\nConfiguring gLite Security Utilities                      ",
            glib.printFailedMessage()
        else:
            print "\nConfiguring gLite Security Utilities                      ",
            glib.printOkMessage()
        
        # Create the GLITE_USER if it doesn't exists
        print "\nCreating/Verifying the GLITE_USER account %s" % os.environ['GLITE_USER']
        (uid,gid) = glib.get_user_info(os.environ['GLITE_USER'])
        glib.check_dir(os.environ['GLITE_LOCATION_VAR'],0755, uid, gid)
        lb_cert_path = pwd.getpwnam(os.environ['GLITE_USER'])[5] + "/" + params['user.certificate.path']
        glib.check_dir(lb_cert_path ,0755, uid, gid)
        glib.printOkMessage()

        # Create all directories needed
        glib.check_dir(os.environ['GLITE_CERT_DIR'])
        print "\nVerify CA certificates directory                          ",
        glib.printOkMessage()
         
        # Copy certificates
        print "\nCopy host certificates to GLITE_USER home directory as service certificates",
        os.system("cp %s %s %s/" % (params['host.certificate.file'], params['host.key.file'], lb_cert_path))
        os.chown("%s/hostcert.pem" % lb_cert_path, uid,gid)
        os.chmod("%s/hostcert.pem" % lb_cert_path, 0644)
        os.chown("%s/hostkey.pem" % lb_cert_path, uid,gid)
        os.chmod("%s/hostkey.pem" % lb_cert_path, 0400)
        glib.printOkMessage()

        #--------------------------------------------------------
        # Configure MySQL
        #--------------------------------------------------------

        # Set mysql parameters
        #self.mysql.setConfiguration('mysql','loose-max_allowed_packet',params['mysql.max_allowed_packet'])
        self.mysql.setConfiguration('mysqld','max_allowed_packet',params['mysql.max_allowed_packet'])
        
        # start MySQL
        self.mysql.stop()
        time.sleep(5)
        self.mysql.start()                

        if not os.path.exists('/tmp/mysql.sock'):
            os.symlink('/var/lib/mysql/mysql.sock', '/tmp/mysql.sock')

        # ------------------------------------------------------------
        # Check password of MySQL
        # ------------------------------------------------------------
        
        self.mysql_root_password = params['mysql.root.password']
        if not params.has_key('set.mysql.root.password'):
            params['set.mysql.root.password'] = '******'
        setempty = params['set.mysql.root.password']
        if self.mysql.checkMySQLConfiguration(self.mysql_root_password,setempty):
            return 1
        
        # Create the MySQL database
        print "\nCreate/Verify the %s database" % params['lb.database.name']
        
        # Check if database exists
        if self.mysql.existsDB(params['lb.database.name'],self.mysql_root_password) != 0:
            # Create database
            print ('\n==> Creating MySQL %s database\n' % params['lb.database.name'])
    
            if os.path.exists('/bin/rm /tmp/mysql_ct'):
                os.remove('/tmp/mysql_ct')
            
            file = open('/tmp/mysql_ct', 'w')

            self.mysql.add_user(params['lb.database.name'],params['lb.database.username'],"",self.mysql_root_password)
            text = ['USE %s;\n' % params['lb.database.name'],
                    '\. %s/etc/glite-lb-dbsetup.sql\n' % os.environ['GLITE_LOCATION']]
    
            file.writelines(text)
            file.close()
            os.system('/usr/bin/mysql -p%s < /tmp/mysql_ct' % self.mysql_root_password)
            os.system('/bin/rm /tmp/mysql_ct')
            
            #Starting and stopping the database before the index creation
            self.mysql.stop()
            time.sleep(5)
            self.mysql.start()

            #Creating the indexes
            print 'Creating the index configuration file %s/etc/glite-lb-index.conf            ' % os.environ['GLITE_LOCATION'],
            path = "%s/etc/glite-lb-index.conf" % os.environ['GLITE_LOCATION']
            pathBak = "%s/etc/glite-lb-index.conf.bak" % os.environ['GLITE_LOCATION']
        
            if os.path.exists(pathBak):
                os.remove(pathBak)
            if os.path.exists(path):
                os.rename(path,pathBak)
            file = open(path, 'w')
            file.write("[\n")
            file.write("        JobIndices = {\n")
            for index in params['lb.index.list']:
                file.write("                [ type = \"system\"; name = \"%s\" ],\n" % index)
            file.write("        }\n")
            file.write("]\n")
            file.close()
            glib.printOkMessage()
            
            print "Running glite-lb-bkindex                    ",    
            if os.system('%s/bin/glite-lb-bkindex -r %s/etc/glite-lb-index.conf' % (os.environ['GLITE_LOCATION'],os.environ['GLITE_LOCATION'])):
                glib.printFailedMessage()
                return 1
            else:
                glib.printOkMessage()
        
        else:
            print "\n==> MySQL database %s already exist\n" % params['lb.database.name']
            
        self.mysql.stop()
    
        #-------------------------------------------------------------------
        # RGMA servicetool: configure servicetool
        #-------------------------------------------------------------------

        if params['rgma.servicetool.activate'] == "true":
            
            # Instantiate the rgma-servicetool class
            rgmaServicetool = gliteRgmaServicetool()
            rgmaServicetool.verbose = self.verbose
            
            # Create Local Logger instance
            serviceId = "%s_%s" % (glib.fq_hostname, params['lbserver.serviceType'])
            servicetoolInstance = gliteRgmaServicetoolInstance(glib, serviceId)
            
            # set params
            servicetoolInstance.setServiceName(params['lbserver.serviceName'])
            servicetoolInstance.setServiceType(params['lbserver.serviceType'])
            servicetoolInstance.setServiceVersion(self.version)
            servicetoolInstance.setStatusScript(params['lbserver.statusScript'])
            servicetoolInstance.setEndpoint(params['lbserver.endpoint'])
            
            # add instance to the gLite configuration
            if servicetoolInstance.add() == 1:
                return 1
            
            # Configure servicetool
            if rgmaServicetool.configure(glib):
                # error in configuring servicetool
                return 1
            
        return 0
コード例 #2
0
        sys.exit(1)
    
    verbose = 0
    if params.has_key('glite.installer.verbose'):
        if params['glite.installer.verbose'] == "true":
            verbose = 1
    glib.verbose = verbose
    
    # Set up the environment
    set_env()
          
    # Instantiate the service classes
    service = glite_lb()
    service.verbose = verbose
    # Instantiate the rgma servicetool class
    rgmaServicetool = gliteRgmaServicetool()
    rgmaServicetool.verbose = verbose	
    
    # Command line opts if any
    try:
        opts, args = glib.getopt(sys.argv[1:], 'chv', ['checkconf', 'help', 'version','configure','stop','start','status','siteconfig='])
    except getopt.GetoptError:
        service.usage(msg = "Unknown options(s)")
        sys.exit(1)

    if len(opts) == 0:
        service.usage()
        sys.exit(0)
    
    # Check cli options
    for o, a in opts: