Eric

jeudi août 27, 2009

OpenDS 1.2 SMF (service management facility)

Comment faire pour ajouter OpenDS au service SMF.

  • Ajouter au service
  • # ./opends-smf.bash -a enable -n ds1 -i /opt/OpenDS-1.2.0
    # ./opends-smf.bash -a list
    STATE          STIME    FMRI
    offline*       13:45:12 svc:/network/opends/server:ds1
    
  • Mettre le service désactivé
  • # ./opends-smf.bash -a disable -n ds1
    # ./opends-smf.bash -a list
    STATE          STIME    FMRI
    disabled       13:47:02 svc:/network/opends/server:ds1
    
  • Afficher l'état du service
  • # svcs -x ds1
    svc:/network/opends/server:ds1 (OpenDS LDAP directory server)
     State: disabled since August 27, 2009  1:47:02 PM EDT
    Reason: Disabled by an administrator.
       See: http://sun.com/msg/SMF-8000-05
       See: /var/svc/log/network-opends-server:ds1.log
    Impact: This service is not running.
    
  • démarrer le service
  • # svcadm enable ds1
    # svcs -x ds1
    svc:/network/opends/server:ds1 (OpenDS LDAP directory server)
     State: online since August 27, 2009  1:48:40 PM EDT
       See: /var/svc/log/network-opends-server:ds1.log
    Impact: None.
    
  • Supprimer de service du SMF
  • # ./opends-smf.bash -a unconfigure -n ds1
    # ./opends-smf.bash -a list
    STATE STIME FMRI
    

    Code:

    # vi opends-smf.bash
    # chmod +x opends-smf.bash
    
    #!/bin/bash
    #
    # CDDL HEADER START
    #
    # The contents of this file are subject to the terms of the
    # Common Development and Distribution License, Version 1.0 only
    # (the "License").  You may not use this file except in compliance
    # with the License.
    #
    # You can obtain a copy of the license at
    # trunk/opends/resource/legal-notices/OpenDS.LICENSE
    # or https://OpenDS.dev.java.net/OpenDS.LICENSE.
    # See the License for the specific language governing permissions
    # and limitations under the License.
    #
    # When distributing Covered Code, include this CDDL HEADER in each
    # file and include the License file at
    # trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
    # add the following below this CDDL HEADER, with the fields enclosed
    # by brackets "[]" replaced with your own identifying information:
    #      Portions Copyright [yyyy] [name of copyright owner]
    #
    # CDDL HEADER END
    #
    #
    #      Copyright 2006-2008 Sun Microsystems, Inc.
    
    
    ##############################################################################
    #
    # The purpose of this script is to provide a single script to provide the
    # following Solaris 10 Service Management Facility (SMF) capabilities to 
    # OpenDS 2.0.0:
    #   * Configure a specific OpenDS instance for SMF
    #   * [Enable|Start] a specific OpenDS instance via SMF
    #   * [Disable|Stop] a specific OpenDS instance via SMF
    #   * Unconfigure an OpenDS instance from SMF
    #   * List OpenDS instances
    #
    ##############################################################################
    #
    # Define global default variables
    #
    manifest="$HOME/.opends_manifest.$$"
    
    ##############################################################################
    #
    # Find pager
    #
    findpager() {
       #
       # Set the page command
       #
       pgcmd='cat - '
       ck4less=`which less 2>&1 | /usr/bin/grep -v "no less"`
       if [ -n "${ck4less}" ]
       then
          pgcmd='less'
       else
          ck4more=`which more 2>&1 | /usr/bin/grep -v "no more"`
          if [ -n "${ck4more}" ]
          then
             pgcmd='more'
          fi
       fi
    }
    
    ##############################################################################
    #
    # Define appropriate usage
    #
    usage() {
       errmsg=${1}
    
       findpager
    
       cat < 
    System Administration Commands                        opends-smf(1M)
    
    NAME
         opends-smf - set up and manage OpenDS SMF instances
    
    
    SYNOPSIS
         Normal usage:
         opends-smf -a  [options]
    
         See proper usage:
         opends-smf -h
    
    DESCRIPTION
         The purpose of opends-smf is to simplify Solaris 10 zones
         management.  There are many pre-defined actions that can be
         applied to one or more zones depending on the action.
    
         The purpose of opends-smf is to provide a single script to 
         provide simplified integration of OpenDS instances into the 
         Solaris 10 Service Management Facility (SMF).
    
    
    OPTIONS
         The following options are supported:
    
         -a      Specify the action to be performed
    
         -n    SMF Instance Name
    
         -i   Directory of the OpenDS instance.
    
         -u        Specify the run-time user of the OpenDS instance.
    
         -g       Specify the run-time group of the OpenDS instance.
    
         -h              See this usage information
    
    ACTIONS
         The following actions are supported:
            list: List SMF enabled OpenDS instances
    
            configure: Create an SMF manifest and import it for a particular OpenDS instance.
    
            unconfigure: Export the SMF configuration for a particular OpenDS instance.
    
            enable|start: Enable or start a particular OpenDS instance
    
            disable|stop: Disable or stop a particular OpenDS instance
    
            restart: Disable or stop a particular OpenDS instance followed by Enable or starting
              of the same OpenDSinstance.
    
    
    EXIT STATUS
         The following exit values are returned:
    
         0        Successful completion.
    
         1        An error occurred.
    
         2        Invalid usage.
    
    
    SEE ALSO
         smf(5), pfexec(1)
    
    EOF
    
       if [ -n "${errmsg}" ]; then echo "${errmsg}";fi
    
       exit 2
    }
    
    ############################################################################
    #
    # Define exit level error message routine
    #
    error_message() {
       if [ -f "${manifest}" ]; then rm -f "${manifest}"; fi
       errmsg=${1}
       if [ -n "${errmsg}" ]
       then
          echo -e "Error: ${errmsg}"
          exit 1
       fi
    }
    
    ##############################################################################
    #
    # Validate the user and group existence and OpenDS ownership
    #
    validate_ownership() {
       ck4user=`/usr/bin/grep "^$user:" /etc/passwd`
       if [ -z "${ck4user}" ]; then error_message "The operating system user ($user) must exist."; fi
    
       ck4uowner=`/usr/bin/ls -ald $inst_dir | /usr/bin/awk '{ print $3 }'`
       if [ "$ck4uowner" != "$user" ]; then error_message "The specified user ($user) does not match the OpenDS instance user ownership ($ck4uowner)."; fi
     
       ck4group=`/usr/bin/grep "^$group:" /etc/group`
       if [ -z "${ck4group}" ]; then error_message "The operating system group ($group) must exist."; fi
    
       ck4gowner=`/usr/bin/ls -ald $inst_dir | /usr/bin/awk '{ print $4 }'`
       if [ "$ck4gowner" != "$group" ]; then error_message "The specified group ($group) does not match the OpenDS instance group ownership ($ck4gowner)."; fi
    }
    
    ##############################################################################
    #
    # Make and import manifest
    #
    configure_smf() {
       # Qualify the import request
    
       if [ -z "${inst_name}" ]; then error_message "Must provide instance name via -n "; fi
       ck4smf=`/usr/bin/svcs -a svc:/network/opends/server:$inst_name 2>&1 | /usr/bin/grep "svc:/network/opends/server:$inst_name$"`
       if [ -n "$ck4smf" ]; then error_message "OpenDS instance \"$inst_name\" already exists."; fi
    
       if [ -z "${inst_dir}" ];  then error_message "Must provide instance path via -i "; fi
       if [ -d "${inst_dir}" ];  then true; else error_message "OpenDS Instance directory \"${inst_dir}\" does not exist."; fi
    
       validate_ownership;
    
       cat << EOF > "$manifest"
    
    
    
    
        
            
            
          	
                
                    
                
         	
                
                    
                
                
                    
                        
                    
                
                
                    
                        
                    
                
                
                
                    
                
                
                
                    
                    
                
                
            
            
        
    
    EOF
       /usr/sbin/svccfg import "$manifest"
       if [ "$?" -ne 0 ]
       then
          error_message "SMF Import Failed!"
       fi
    }
    
    enable_smf() {
       validate_ownership
    
       ck4smf=`/usr/bin/svcs -a svc:/network/opends/server:$inst_name 2>&1 | /usr/bin/grep "doesn't match any instances"`
       if [ -n "$ck4smf" ]; then configure_smf; fi
    
       if [ -z "${inst_name}" ]; then error_message "Must provide instance name via -n "; fi
       /usr/sbin/svcadm enable $inst_name
    }
    
    disable_smf() {
       if [ -z "${inst_name}" ]; then error_message "Must provide instance name via -n "; fi
    
       # Don't exit until the service finishes shutting down
       ck4state=`/usr/bin/svcs -aH svc:/network/opends/server:$inst_name 2> /dev/null | awk '{ print $1 }'`
       if [ -n "$ck4state" ]
       then
          /usr/sbin/svcadm disable svc:/network/opends/server:$inst_name
          while [ "$ck4state" != 'disabled' ]
          do
             sleep 3
             /usr/sbin/svcadm disable svc:/network/opends/server:$inst_name
             ck4state=`/usr/bin/svcs -aH svc:/network/opends/server:$inst_name 2> /dev/null | awk '{ print $1 }'`
          done
       fi
    }
    
    unconfigure_smf() {
       if [ -z "${inst_name}" ]; then error_message "Must provide instance name via -n "; fi
       disable_smf
       /usr/sbin/svccfg delete $inst_name
    }
    
    list_smf() {
       /usr/bin/svcs -a | /usr/bin/egrep "FMRI|svc:/network/opends/server:$inst_name"
    }
    
    ##############################################################################
    #
    # Ensure this program is run as the root user
    #
    ck4root=`id | cut -d'(' -f2 | cut -d ')' -f1`
    if [ "$ck4root" != 'root' ];then error_message "Must run as root user."; fi
       
    ##############################################################################
    #
    # If any parameters were passed evaluate their usage...
    #
    while getopts ha:n:i:u:g: OPT
    do
       case ${OPT} in
       h|+h) usage;;
       a|+a) if [ -z "${OPTARG}" ];then error_message "Must provide a valid action with the -a flag";fi
             action="${OPTARG}"
             ;;
       n|+n) if [ -z "${OPTARG}" ];then error_message "Must provide a valid OpenDS instance name with the -n flag";fi
             inst_name="${OPTARG}"
             ;;
       i|+i) if [ -z "${OPTARG}" ];then error_message "Must provide a valid OpenDS instance directory with the -i flag";fi
             inst_dir="${OPTARG}"
             ;;
       u|+u) if [ -z "${OPTARG}" ];then error_message "Must provide a valid and unused user name with the -u flag";fi
             user="${OPTARG}"
             ;;
       g|+g) if [ -z "${OPTARG}" ];then error_message "Must provide a valid and unused group name with the -g flag";fi
             group="${OPTARG}"
             ;;
          *) usage;;
       esac
    done
    shift `expr ${OPTIND} - 1`
    
    ##############################################################################
    #
    # Test usage
    #
    if  [ -z "${action}" ]; then error_message "Must provide action via -a "; fi
    
    ##############################################################################
    #
    # Set user and group info
    #
    if [ -z "$user" ]
    then
       user=`/usr/bin/svcprop -p start/user svc:/network/opends/server:$inst_name 2> /dev/null`
       if [ -z "$user" ]
       then
          if [ -n "$inst_dir" ]
          then
             user=`/usr/bin/ls -ald $inst_dir | /usr/bin/awk '{ print $3 }'`
          fi
       fi
       if [ -z "$user" ]; then user='ldap'; fi
    fi
    
    if [ -z "$group" ]
    then
       group=`/usr/bin/svcprop -p start/group svc:/network/opends/server:$inst_name 2> /dev/null`
       if [ -z "$group" ]
       then
          if [ -n "$inst_dir" ]
          then
             group=`/usr/bin/ls -ald $inst_dir | /usr/bin/awk '{ print $4 }'`
          fi
       fi
       if [ -z "$group" ]; then group='ldap'; fi
    fi
    
    case ${action} in
          'configure') configure_smf;;
        'unconfigure') unconfigure_smf;;
             'enable') enable_smf;;
              'start') enable_smf;;
            'disable') disable_smf;;
               'stop') disable_smf;;
            'restart') disable_smf; enable_smf;;
               'list') list_smf;;
                    *) usage;;
    esac
    

    Comments:

    Post a Comment:
    Comments are closed for this entry.

    Calendar

    Feeds

    Search

    Links

    Navigation

    Referrers