From 43bc1f9b5a278cb88935bd3ad87951ccc22c1d31 Mon Sep 17 00:00:00 2001 From: Alberto Di Meglio Date: Fri, 3 Dec 2004 00:48:39 +0000 Subject: [PATCH] Updated to use default format and functions --- .../config/scripts/glite-lb-config.py | 228 ++++++++++++++++----- .../config/templates/glite-lb.cfg.xml | 38 +++- 2 files changed, 209 insertions(+), 57 deletions(-) diff --git a/org.glite.deployment.lb/config/scripts/glite-lb-config.py b/org.glite.deployment.lb/config/scripts/glite-lb-config.py index 0b751cb..d4f77fb 100644 --- a/org.glite.deployment.lb/config/scripts/glite-lb-config.py +++ b/org.glite.deployment.lb/config/scripts/glite-lb-config.py @@ -1,46 +1,100 @@ #!/usr/bin/env python -##################################################################################### -# -# Template script for configuring the gLite LB service -# David Collados -# and -# Robert Harakaly -# -# $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 +# Leanne Guy # -# 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 diff --git a/org.glite.deployment.lb/config/templates/glite-lb.cfg.xml b/org.glite.deployment.lb/config/templates/glite-lb.cfg.xml index f1c2c8d..54b0605 100644 --- a/org.glite.deployment.lb/config/templates/glite-lb.cfg.xml +++ b/org.glite.deployment.lb/config/templates/glite-lb.cfg.xml @@ -1,14 +1,36 @@ - - - - - - + + + + + + + + + + - - + + + + + + + + + + + + \ No newline at end of file -- 1.8.2.3