Updated to use default format and functions
authorAlberto Di Meglio <alberto.di.meglio@cern.ch>
Fri, 3 Dec 2004 00:48:39 +0000 (00:48 +0000)
committerAlberto Di Meglio <alberto.di.meglio@cern.ch>
Fri, 3 Dec 2004 00:48:39 +0000 (00:48 +0000)
org.glite.deployment.lb/config/scripts/glite-lb-config.py
org.glite.deployment.lb/config/templates/glite-lb.cfg.xml

index 0b751cb..d4f77fb 100644 (file)
 #!/usr/bin/env python
-#####################################################################################
-#
-# Template script for configuring the gLite LB service
-# David Collados <david.collados@cern.ch>
-#   and
-# Robert Harakaly <robert.harakaly@cern.ch>
-#
-# $Id:
-#
-#####################################################################################
+################################################################################
 #
 # Copyright (c) Members of the EGEE Collaboration. 2004.
 # See http://eu-egee.org/partners/ for details on the copyright holders.
 # For license conditions see the license file or http://eu-egee.org/license.html
 #
-#####################################################################################
-
-#####################################################################################
+################################################################################
+# glite-lb-config v. 0.1.0
+#
+# Post-installation script for configuring the gLite Logging and Bookkeping Server
+# Robert Harakaly < robert.harakaly@cern.ch >
+# Diana Bosio <Diana.Bosio@cern.ch>
+# Leanne Guy <leanne.guy@cern.ch>
 #
-#    Used configuration parameters
+# Version info: $Id$
 #
-#    lb.database.name
-#    lb.database.username
+# Usage: python glite-lb-config [-c|-v|-h|--help]
+#        -c          print configuration
+#        -v          print version
+#        -h,--help   print usage info
 #
-#####################################################################################
+# Return codes: 0 - Ok
+#               1 - Configuration failed
+#
+################################################################################
+
 import os,string
 import sys, posix
-import getopt
-import _xmlplus
-import _xmlplus.xpath as xpath
-import xml.dom.minidom
-import time
 
-sys.path.append(".")
 import mysql as MySQL
-from gLiteInstallerLib import gLib as GLib
-
 
-global mysql
-global params
+# Set global variables here 
+global params                         # all config values from the XML file
 
 class glite_lb:
+
+    def __init__(self):
+        self.verbose = 'false'
+        
+        self.version = "0.1.0"
+        self.name = "glite-lb"
+        self.friendly.name = "gLite Logging and Bookkeeping Server"
+        
+    #-------------------------------------------------------------------------------
+    # Banner 
+    #-------------------------------------------------------------------------------
+
+    def banner(self):
+
+        print "\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+        print "Configuring the %s" % self.friendly.name
+        print "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"
+    
+    #-------------------------------------------------------------------------------
+    # Copyright 
+    #-------------------------------------------------------------------------------
+
+    def copyright(self):
+
+        print '\nCopyright (c) Members of the EGEE Collaboration. 2004'
+        print 'See http://eu-egee.org/partners/ for details on the copyright holders'
+        print 'For license conditions see the license file or http://eu-egee.org/license.html'
+
+    #-------------------------------------------------------------------------------
+    # Version
+    #-------------------------------------------------------------------------------
+
+    def version(self):
+
+        print '\n%s-config  v. %s\n' % (self.name,self.version)
+    
+    #-------------------------------------------------------------------------------
+    # Usage
+    #-------------------------------------------------------------------------------
+
+    def usage(self,msg = ""):
+
+        if msg:
+            print "\n%s" % (msg)
+        
+        self.copyright()
+        self.version()
+    
+        print """Usage: \n
+Edit the configuration file %s.cfg.xml in
+%s/etc.config/templates\n
+save it as %s/etc/config/%s.cfg.xml
+and run the script as follows\n 
+python %s-config [OPTION...]""" % (self.name, os.environ['GLITE_LOCATION'], \
+        os.environ['GLITE_LOCATION'], self.name)
+
+        print '    -c, --checkconf     print the service configuration'
+        print '    -v, --version       print the version of the configuration script'
+        print '    -h, --help          print this usage information'
+        print '\n'
+
     def start(self):
         mysql.start()
         os.system('%s/etc/init.d/glite-lb-bkserverd start' % os.environ['GLITE_LOCATION'])
@@ -73,26 +127,102 @@ class glite_lb:
         time.sleep(5)
         mysql.start()
         
-    def init(self):
-        return 0
-        
+#-------------------------------------------------------------------------------
+# Set all environment variables
+#-------------------------------------------------------------------------------
+
+def set_env():
+
+    # gLite
+    glib.export('GLITE_LOCATION');
+    glib.export('GLITE_LOCATION_VAR');
+    if not os.path.exists(os.environ['GLITE_LOCATION_VAR']):
+        os.mkdir(os.environ['GLITE_LOCATION_VAR'],0755)
+    glib.export('GLITE_LOCATION_LOG');
+    if not os.path.exists(os.environ['GLITE_LOCATION_LOG']):
+        os.mkdir(os.environ['GLITE_LOCATION_LOG'],0755)
+    glib.export('GLITE_LOCATION_TMP');
+    if not os.path.exists(os.environ['GLITE_LOCATION_TMP']):
+        os.mkdir(os.environ['GLITE_LOCATION_TMP'],0755)
+
+    glib.export('GLITE_HOST_CERT',params['host.certificate.file'])
+    glib.export('GLITE_HOST_KEY',params['host.key.file'])
+
+    # bin and lib paths
+    glib.addEnvPath("PATH","/usr/bin/:%s/externals/bin:%s/bin" % (os.environ['GLITE_LOCATION'],os.environ['GLITE_LOCATION']))
+    glib.addEnvPath("LD_LIBRARY_PATH","/usr/lib:%s/externals/lib:%s/lib" % (os.environ['GLITE_LOCATION'],os.environ['GLITE_LOCATION']))
 
-# ---- Main program --
-# Get an instance of the library class
-gLib = GLib()
-
-params = {}
-gLib.loadConfiguration("../glite-lb.cfg.xml",params) 
-gLib.print_params(params)
-os.environ['GLITE_LOCATION'] = params['glite.location']
-gLib.add_user(params['glite.user.name'],params['glite.group.name'])
-gLib.check_dir_perms(params['glite.location']+"/var",0777)
-if params['glite.installer.checkcerts']:
-   gLib.check_certs(params)
-mysql = MySQL.Mysql()
-lb = glite_lb()
-lb.configure()
-os.environ['LD_LIBRARY_PATH'] = params['glite.location'] + "/lib:" + params['globus.location'] + "/lib:"
-os.environ['GLITE_HOST_CERT'] = params['host.certificate.file']
-os.environ['GLITE_HOST_KEY'] = params['host.key.file']
-lb.start()
+    # Set environment
+    glib.setUserEnv()
+    
+#-------------------------------------------------------------------------------
+#  Main program begins here 
+#-------------------------------------------------------------------------------
+
+if __name__ == '__main__':
+
+    # Command line opts if any
+    try:
+        opts, args = getopt.getopt(sys.argv[1:], 'chv', ['checkconf', 'help', 'version'])
+    except getopt.GetoptError:
+        usage(msg = "Unknown options(s)")
+        sys.exit(1)
+
+    # Get an instance of the library class
+    glib = gLib()
+
+    # Load parameters
+    params = {}
+    if glib.loadConfiguration("%s/../glite-lb.cfg.xml" % glib.getScriptPath(),params):
+        print "An error occurred while configuring the service"
+        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
+    mysql = MySQL.Mysql()
+    service = glite_lb()
+    service.verbose = verbose
+    
+    # Print configuration parameters
+    if verbose:
+        glib.print_params(params)
+
+    # Check cli options
+    for o, a in opts:
+        if o in ("-h", "--help"):
+            service.usage()
+            sys.exit(0)
+        if o in ("-v", "--version"):
+            service.version()
+            sys.exit(0)
+        if o in ("-c", "--checkconf"):
+            service.copyright()
+            service.version()
+            glib.print_params(params)
+            sys.exit(0)
+
+    service.copyright()
+    service.version()
+    service.banner()
+        
+    # Configure the service
+    if service.configure() == 0:
+        print "%s configuration successfully completed\n" % service.friendly.name
+    else:
+        print "An error occurred while configuring the %s" % service.friendly.name
+        sys.exit(1)
+        
+    # Start the service
+    if service.start() != 0:
+        print "An error occurred while strating the %s" % service.friendly.name
+        sys.exit(1)
+        
+        
\ No newline at end of file
index f1c2c8d..54b0605 100644 (file)
@@ -1,14 +1,36 @@
 <!--  Parameters for  configuring the org.glite.data.io-daemon service -->
 <config>
        <parameters>
-               <glite.installer.verbose value='true'/>
-               <!-- host certificate -->
-               <glite.installer.checkcerts value='true'/>
-               <!-- user account -->
-               <glite.user.name value="glite"/>
-               <glite.group.name value="glite"/>
+
+               <!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
+               <!-- User-defined parameters - Please change them -->
+               <!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
+
+               <!-- gLite configuration -->
+               <glite.installer.verbose
+                       description="Enable verbose output"
+                       value="true"/>
+                       
+               <glite.installer.checkcerts
+                       description="Enable check of host certificates"
+                       value="true"/>
+
                <!-- MySQL DB -->
-               <lb.database.name value='lbserver20'/>
-               <lb.database.username value='lbserver'/>
+               <lb.database.name
+                       description="The mySQL database name to create for storing LB data"
+                       value="changeme"/>
+                       
+               <lb.database.username
+                       description="The username to be used to access the local mySQL server"
+                       value="changeme"/>
+                       
+               <!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
+               <!-- Optimization parameters - Change them if you know what you're doing -->
+               <!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
+
+               <!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
+               <!-- System parameters - You should leave these alone -->
+               <!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
+
        </parameters>
 </config>
\ No newline at end of file