From d8907de6d65a251e31e71f544f1f073a4a49fdae Mon Sep 17 00:00:00 2001 From: David Collados Date: Sat, 9 Oct 2004 14:32:18 +0000 Subject: [PATCH] LB configuration script in python + parameters file + a patched version of the init.d/glite-lb-bkserverd file that is needed by now. --- org.glite.deployment.lb/config/glite-lb-bkserverd | 98 ++++++ org.glite.deployment.lb/config/glite-lb-config.xml | 21 ++ org.glite.deployment.lb/config/glite-lb-install | 343 +++++++++++++++++++++ 3 files changed, 462 insertions(+) create mode 100644 org.glite.deployment.lb/config/glite-lb-bkserverd create mode 100644 org.glite.deployment.lb/config/glite-lb-config.xml create mode 100755 org.glite.deployment.lb/config/glite-lb-install diff --git a/org.glite.deployment.lb/config/glite-lb-bkserverd b/org.glite.deployment.lb/config/glite-lb-bkserverd new file mode 100644 index 0000000..782ef18 --- /dev/null +++ b/org.glite.deployment.lb/config/glite-lb-bkserverd @@ -0,0 +1,98 @@ +#!/bin/sh + +GLITE_LOCATION=/opt/glite +GLITE_USER=glite +GLITE_LOCATION_VAR=/opt/glite/var +GLITE_TMP=/tmp + +[ -f /etc/glite.conf ] && . /etc/glite.conf +[ -f $HOME/.glite.conf ] && . $HOME/.glite.conf + +[ -f $GLITE_LOCATION/etc/lb.conf ] && . $GLITE_LOCATION/etc/lb.conf +[ -f $GLITE_LOCATION_VAR/etc/lb.conf ] && . $GLITE_LOCATION_VAR/etc/lb.conf + +[ -n "$GLITE_LB_SERVER_PIDFILE" ] && pidfile=$GLITE_LB_SERVER_PIDFILE || + pidfile=$GLITE_LOCATION_VAR/glite-lb-bkserverd.pid + +X509_USER_PROXY=${GLITE_TMP}/hostproxy.pem + +export X509_USER_PROXY + +proxy() +{ + proxyerr=`"${GLOBUS_LOCATION}/bin/grid-proxy-init" -q \ + -cert "$GLITE_HOST_CERT" \ + -key "$GLITE_HOST_KEY" \ + -hours 24 \ + -out "${X509_USER_PROXY}.$$" 2>&1` + + [ $? -eq 0 ] || do_failure "$proxyerr" + + moveerr=`chmod 400 "${X509_USER_PROXY}.$$" && + chown "${GLITE_USER}" "${X509_USER_PROXY}.$$" && + mv "${X509_USER_PROXY}.$$" "${X509_USER_PROXY}" 2>&1` + [ $? -eq 0 ] || do_failure "$moveerr" +} + + +start() +{ + proxy + + [ -n "$GLITE_HOST_CERT" -a -n "$GLITE_HOST_KEY" ] && + creds="-c $GLITE_HOST_CERT -k $GLITE_HOST_KEY" + + [ -z "$creds" ] && echo $0: WARNING: No credentials specified. Using default lookup which is dangerous. >&2 + + [ -n "$GLITE_LB_SERVER_PORT" ] && port="-p $GLITE_LB_SERVER_PORT" + + echo -n Starting glite_lb_bkserver ... + su $GLITE_USER -c "$GLITE_LOCATION/bin/glite-lb-bkserverd \ + $creds -C $X509_CERT_DIR -i $pidfile &" && echo " done" +} + +stop() +{ + if [ -f $pidfile ]; then + pid=`cat $pidfile` + kill $pid + echo -n Stopping glite-lb-bkserverd \($pid\) ... + try=0 + while ps p $pid >/dev/null 2>&1; do + sleep 1; + try=`expr $try + 1` + if [ $try = 20 ]; then + echo " giving up after $try retries" + return 1 + fi + done + echo " done" + rm -f $pidfile + else + echo $pidfile does not exist - glite-lb-bkserverd not running? >&2 + return 1 + fi +} + +status() +{ + if [ -f $pidfile ]; then + pid=`cat $pidfile` + if ps p $pid >/dev/null 2>&1; then + echo glite-lb-bkserverd running as $pid + return 0 + fi + fi + + echo glite-lb-bkserverd not running + return 1 +} + +case x$1 in + xstart) start;; + xstop) stop;; + xrestart) stop; start;; + xstatus) status;; + x*) echo usage: $0 start,stop,restart,status >&2 + exit 1;; +esac diff --git a/org.glite.deployment.lb/config/glite-lb-config.xml b/org.glite.deployment.lb/config/glite-lb-config.xml new file mode 100644 index 0000000..4bc1c2e --- /dev/null +++ b/org.glite.deployment.lb/config/glite-lb-config.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/org.glite.deployment.lb/config/glite-lb-install b/org.glite.deployment.lb/config/glite-lb-install new file mode 100755 index 0000000..ed9b6c4 --- /dev/null +++ b/org.glite.deployment.lb/config/glite-lb-install @@ -0,0 +1,343 @@ +#!/usr/bin/env python +##################################################################################### +# +# Template script for configuring the gLite LB service +# David Collados +# $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 +# +##################################################################################### + +import os,string +import sys, posix +import getopt +import _xmlplus +import _xmlplus.xpath as xpath +import xml.dom.minidom +import time +from xml.dom.minidom import Node + + +# Set global variables here +global config +global nodeType +nodeType = "lb" +global verbose +global certs + +#------------------------------------------------------------------------------- +# Print some help +#------------------------------------------------------------------------------- + +def usage(msg='glite-lb-bkserverd start/stop/status'): + pass + +#------------------------------------------------------------------------------- +# Set all environment variables +#------------------------------------------------------------------------------- + +def set_env(): + os.environ['GLITE_LOCATION'] = config['glite_location'] + os.environ['GLOBUS_LOCATION'] = config['globus_location'] + os.environ['LD_LIBRARY_PATH'] = '%s/lib:/%s/lib:$LD_LIBRARY_PATH' % (config['glite_location'], config['globus_location']) + os.environ['GLITE_HOST_KEY'] = config['hostkey'] + os.environ['GLITE_HOST_CERT'] = config['hostcert'] + os.environ['GLITE_CERT_DIR'] = config['certs_path'] + + print '#-------------------------------------------------------------------' + print 'Setting ENV variables in /root/.bashrc and /root/.profile' + print '#-------------------------------------------------------------------' + file = open('/root/.bashrc', 'a') + file.write('\nexport GLITE_LOCATION=%s\n' % config['glite_location']) + file.write('export GLOBUS_LOCATION=%s\n' % config['globus_location']) + file.write('export LD_LIBRARY_PATH=$GLITE_LOCATION/lib:$GLOBUS_LOCATION/lib:$LD_LIBRARY_PATH]\n') + file.write('export GLITE_HOST_KEY=%s\n' % config['hostkey']) + file.write('export GLITE_HOST_CERT=%s\n' % config['hostcert']) + file.write('export GLITE_CERT_DIR=%s\n\n' % config['certs_path']) + file.close() + file = open('/root/.profile', 'a') + file.write('\nexport GLITE_LOCATION=%s\n' % config['glite_location']) + file.write('export GLOBUS_LOCATION=%s\n' % config['globus_location']) + file.write('export LD_LIBRARY_PATH=$GLITE_LOCATION/lib:$GLOBUS_LOCATION/lib:$LD_LIBRARY_PATH]\n') + file.write('export GLITE_HOST_KEY=%s\n' % config['hostkey']) + file.write('export GLITE_HOST_CERT=%s\n' % config['hostcert']) + file.write('export GLITE_CERT_DIR=%s\n\n' % config['certs_path']) + file.close() + print 'OK!\n' + + print '#-------------------------------------------------------------------' + print ('Setting ENV variables in /home/%s/.bashrc and /home/%s/.profile' % (config['username'], config['username'])) + print '#-------------------------------------------------------------------' + file = open('/home/%s/.bashrc' % config['username'], 'a') + file.write('\nexport GLITE_LOCATION=%s\n' % config['glite_location']) + file.write('export GLOBUS_LOCATION=%s\n' % config['globus_location']) + file.write('export LD_LIBRARY_PATH=$GLITE_LOCATION/lib:$GLOBUS_LOCATION/lib:$LD_LIBRARY_PATH]\n') + file.write('export GLITE_HOST_KEY=%s\n' % config['hostkey']) + file.write('export GLITE_HOST_CERT=%s\n' % config['hostcert']) + file.write('export GLITE_CERT_DIR=%s\n\n' % config['certs_path']) + file.close() + file = open('/home/%s/.profile' % config['username'], 'a') + file.write('\nexport GLITE_LOCATION=%s\n' % config['glite_location']) + file.write('export GLOBUS_LOCATION=%s\n' % config['globus_location']) + file.write('export LD_LIBRARY_PATH=$GLITE_LOCATION/lib:$GLOBUS_LOCATION/lib:$LD_LIBRARY_PATH]\n') + file.write('export GLITE_HOST_KEY=%s\n' % config['hostkey']) + file.write('export GLITE_HOST_CERT=%s\n' % config['hostcert']) + file.write('export GLITE_CERT_DIR=%s\n\n' % config['certs_path']) + file.close() + os.system('/bin/chown %s:%s /home/%s/.bashrc' % (config['username'], config['group_name'], config['username'])) + os.system('/bin/chown %s:%s /home/%s/.profile' % (config['username'], config['group_name'], config['username'])) + print 'OK!\n' + +#------------------------------------------------------------------------------- +# Check the environment is correctly set +#------------------------------------------------------------------------------- + +def check_env(): + if (os.environ['GLITE_LOCATION'] == '/opt/glite'): + return 1 + else: + sys.exit('GLITE_LOCATION env variable not set!') + + +#------------------------------------------------------------------------------- +# Display the service configuration parameters +#------------------------------------------------------------------------------- + +def print_config(config): + print '#-------------------------------------------------------------------' + print 'Configuration parameters for the gLite %s installation: ' % (nodeType) + print '#-------------------------------------------------------------------' + + for x in config.keys(): + print '%s = %s ' % (x, config[x]) + + print "\n" + + +#------------------------------------------------------------------------------- +# Display the environment varaibles +#------------------------------------------------------------------------------- + +def print_env(): + + print '#-------------------------------------------------------------------' + print 'Environment variables:' + print '#-------------------------------------------------------------------' + print "GLITE_LOCATION = %s " % os.environ['GLITE_LOCATION'] + print "LD_LIBRARY_PATH = %s " % os.environ['LD_LIBRARY_PATH'] + print "PATH = %s " % os.environ['PATH'] + print "GLITE_HOST_KEY = %s " % os.environ['GLITE_HOST_KEY'] + print "GLITE_HOST_CERT = %s " % os.environ['GLITE_HOST_CERT'] + print "GLITE_CERT_DIR = %s " % os.environ['GLITE_CERT_DIR'] + + print "\n" + + +#------------------------------------------------------------------------------- +# Check to see if host certs exist and that the permissions are correct +#------------------------------------------------------------------------------- + +def check_certs(): + # Check host certicicates exist + print '#-------------------------------------------------------------------' + print 'Checking if the hostkey and hostcert are in the machine.' + print '#-------------------------------------------------------------------' + + hostcert = config['hostcert'] + hostkey = config['hostkey'] + if not os.path.exists(hostcert): + sys.exit("Error: Host certificate not found at %s" % hostcert) + if not os.path.exists(hostkey) : + sys.exit("Error: Host key not found at %s" % hostkey) + + print('OK!\n') + os.chmod(hostcert, 0644) + os.chmod(hostkey, 0600) + +#------------------------------------------------------------------------------- +# All the configuration code goes here +#------------------------------------------------------------------------------- + +def configure(): + # Create the MySQL database + print '#-------------------------------------------------------------------' + print ('Creating MySQL %s database.' % config['db_name']) + print '#-------------------------------------------------------------------' + file = open('/tmp/mysql_ct', 'w') + file.write('CREATE DATABASE %s;\n' % config['db_name']) + file.write('GRANT ALL PRIVILEGES ON %s.* TO %s@localhost IDENTIFIED BY "";\n' % (config['db_name'], config['db_name'])) + file.write('USE %s;\n' % config['db_name']) + file.write('\. %s/etc/glite-lb-dbsetup.sql\n' % config['glite_location']) + file.close() + os.system('/usr/bin/mysql < /tmp/mysql_ct') + + + # Restarting MySQL + print '#-------------------------------------------------------------------' + print 'Restarting MySQL.' + print '#-------------------------------------------------------------------' + os.system('/etc/init.d/mysql stop') + time.sleep(5) # Sleep 5 seconds before starting MySQL + os.system('/etc/init.d/mysql start') + print '\n' + + + # Create var directory + print '#-------------------------------------------------------------------' + print ('Creating %s/var directory.' % config['glite_location']) + print '#-------------------------------------------------------------------' + os.system('/bin/mkdir %s/var' % config['glite_location']) + os.system('/bin/chmod 777 %s/var' % config['glite_location']) + if os.path.exists('%s/var' % config['glite_location']): + print('OK!\n') + else: + sys.exit('Could not create directory %s/var\n' % config['glite_location']) + + + # Copy the temporary glite-lb-bkserverd daemon in init.d + print '#-------------------------------------------------------------------' + print ('Updating %s/etc/init.d/glite-lb-bkserverd' % config['glite_location']) + print '#-------------------------------------------------------------------' + os.system('/bin/cp glite-lb-bkserverd %s/etc/init.d/' % config['glite_location']) + print '\n' + + + return 1 + + +#------------------------------------------------------------------------------- +# Add user and group +#------------------------------------------------------------------------------- + +def create_account(): + # Create the group and user account + print '#-------------------------------------------------------------------' + print ('Adding group name "%s"' % config['group_name']) + print '#-------------------------------------------------------------------' + os.system('/usr/sbin/groupadd %s' % config['group_name']) + file = open('/etc/group', 'r') + group = config['group_name'] + found_group = 0; + for line in file.readlines(): + rec = string.splitfields(line, ':') + if rec[0] == group: + print ('OK!\n') + found_group = 1 + break + if (found_group == 0): + sys.exit('Could not add group: %s' % group) + + print '#-------------------------------------------------------------------' + print ('Adding user "%s" to group "%s"' % (config['username'], config['group_name'])) + print '#-------------------------------------------------------------------' + os.system('/usr/sbin/useradd -s /bin/bash -g %s %s' % (config['group_name'], config['username'])) + file = open('/etc/passwd', 'r') + user = config['username'] + found_user = 0; + for line in file.readlines(): + rec = string.splitfields(line, ':') + if rec[0] == user: + print ('OK!\n') + found_user = 1 + break + if (found_user == 0): + sys.exit('Could not add user: %s' % user) + + + +#------------------------------------------------------------------------------- +# Load the configuration values for the service +#------------------------------------------------------------------------------- + +def LoadParameterFile(filename='config.xml'): + doc = xml.dom.minidom.parse(filename) + + nodes = xpath.Evaluate("/config/parameter", doc.documentElement) + params = {} + for node in nodes: + if params.has_key(node.attributes['name'].nodeValue): + print 'Warning name: %s already defined with value: %s' \ + % (node.attributes['name'].nodeValue, \ + node.attributes['value'].nodeValue) + else: + params[node.attributes['name'].nodeValue] = \ + node.attributes['value'].nodeValue + return params + + +#------------------------------------------------------------------------------- +# Main program begins here +#------------------------------------------------------------------------------- + +if __name__ == '__main__': + + print '#-------------------------------------------------------------------' + print 'Installing a gLite %s' % (nodeType) + print '#-------------------------------------------------------------------' + + # Command line opts if any + try: + opts, args = getopt.getopt(sys.argv[1:], 'h:t', ['help', 'test=']) + except getopt.GetoptError: + usage() + sys.exit(2) + + for o, a in opts: + if o in ("-h", "--help"): + usage('Test message if needed') + sys.exit() + lfn = a + if o == "--test": + var=a + + # The script must be run as root + if not os.geteuid()==0: + sys.exit("\nThis script must be run as root\n") + + # Read service configuration information from a file + configFile = "glite-%s-config.xml" % nodeType + config = LoadParameterFile(configFile) + + # Create user account + create_account() + + # Host certificates + if config['certs'] == 'true': + if not check_certs(): + os.path.isfile("No host certificats found - plase install them and rerun") + + # Verbose + if config['verbose'] == 'true': + verbose = 1 + else: + verbose = 0 + + # Set up the environment + set_env() + check_env() + print_env() + + # Print configuration parameters + if verbose: + print_config(config) + + # Configure the service + if configure(): + print '#-------------------------------------------------------------------' + print ('%s configuration successfully completed' % nodeType) + print '#-------------------------------------------------------------------' + print '\n' + + # Start the daemon + print '#-------------------------------------------------------------------' + print ('Starting the gLite LB daemon using: %s/etc/init.d/glite-lb-bkserverd start' % config['glite_location']) + print '#-------------------------------------------------------------------' + # os.system('/bin/su -l %s -c "%s/etc/init.d/glite-lb-bkserverd start"' % (config['username'], config['glite_location'])) + os.system('%s/etc/init.d/glite-lb-bkserverd start' % config['glite_location']) + print '\n' + -- 1.8.2.3