#!/usr/bin/ksh93 # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # 61haes_r720 src/43haes/usr/sbin/cluster/sa/printServer/sbin/cl_print_server_systemv_monitor.sh 1.4 # # Licensed Materials - Property of IBM # # COPYRIGHT International Business Machines Corp. 2010 # All Rights Reserved # # US Government Users Restricted Rights - Use, duplication or # disclosure restricted by GSA ADP Schedule Contract with IBM Corp. # # IBM_PROLOG_END_TAG # @(#)19 1.4 src/43haes/usr/sbin/cluster/sa/printServer/sbin/cl_print_server_systemv_monitor.sh, hacmp, 61haes_r720, 1522B_hacmp720 5/25/15 19:24:04 ########################################################### # # Name: cleanup # # Description: Cleaning up required resources created. # # Arguments: none # # Returns: N/A # ########################################################### cleanup() { if [[ $VERBOSE_LOGGING == 'high' ]] then PS4_FUNC=cleanup set -x fi # : Cleanup activity : removing print queue : removing the temporary file # KLIB_SA_logmsg INFO 5 1 print_server_sa.cat "Cleanup activity\n" KLIB_SA_logmsg INFO 5 2 print_server_sa.cat "Removing print queue\n" sleep 5 /usr/sbin/lpadmin -x $PRINT_QUEUE >> $LOG_FILE 2>&1 (( $? != 0 )) && { /usr/bin/rm -R /etc/lp/printers/$PRINT_QUEUE /usr/bin/rm /etc/lp/interfaces/$PRINT_QUEUE } KLIB_SA_logmsg INFO 5 3 print_server_sa.cat "Removing temporary file created \ for printing to a file using print queue\n" /usr/bin/rm -rf /dev/$TEMP_FILE >> $LOG_FILE 2>&1 } ########################################################### # # Name: systemv_monitor # # Description: Verify the health of SystemV print subsystem # # Arguments: none # # Returns: # 0 on SUCCESS # 1 on FAILURE # ########################################################### systemv_monitor() { if [[ $VERBOSE_LOGGING == 'high' ]] then PS4_FUNC=systemv_monitor set -x fi KLIB_SA_logmsg INFO 5 4 print_server_sa.cat "%1\$s \ print subsystem Health check initiated\n" "System V" # : printing to a temporary file using SystemV print subsystem : for SystemV print subsystem Health check # KLIB_SA_logmsg INFO 5 5 print_server_sa.cat "Creating a temporary file in /dev directory \ for printing to a file using %1\$s print subsystem\n" "System V" touch /dev/${TEMP_FILE} >> $LOG_FILE 2>&1 (( $? != 0 )) && { # : We are unable to create a new file in /dev, this could be because of : problems with system but print subsystem might function properly. : So just logging a message with returning the value of SUCCESS. # KLIB_SA_logmsg WARN 5 6 print_server_sa.cat "The file creation failed \ for printing to a file using %1\$s print subsystem\n" "System V" KLIB_SA_logmsg WARN 5 7 print_server_sa.cat "The test print to a file \ using print subsystem can't be initiated\n" "System V" return 0 } # : Provide require permissions to file # KLIB_SA_logmsg INFO 5 8 print_server_sa.cat "Providing \ required permission to temporary file created\n" /usr/bin/chmod 600 /dev/${TEMP_FILE} >> $LOG_FILE 2>&1 (( $? != 0 )) && { # : We are unable to provide required permissions to the file, this : could be because of problems with system but print subsystem : might function properly. : So just logging a message with returning the value of SUCCESS. # KLIB_SA_logmsg WARN 5 9 print_server_sa.cat "The required permission modification \ to the temporary file failed.\n" KLIB_SA_logmsg WARN 5 7 print_server_sa.cat "The test print to a file \ using %1\$s subsystem can't be initiated\n" "System V" # : Removing the file created for printing # /usr/bin/rm -rf /dev/${TEMP_FILE} >> $LOG_FILE 2>&1 return 0 } # : Provide required user ownership to file # KLIB_SA_logmsg INFO 5 16 print_server_sa.cat "Providing \ required user ownership to temporary file created\n" /usr/bin/chown lp:lp /dev/${TEMP_FILE} >> $LOG_FILE 2>&1 (( $? != 0 )) && { # : We are unable to modify required ownership to the file, this : could be because of problems with system but print subsystem : might function properly. : So just logging a message with returning the value of SUCCESS. # KLIB_SA_logmsg WARN 5 17 print_server_sa.cat "The required ownership modification \ to the file failed.\n" KLIB_SA_logmsg WARN 5 7 print_server_sa.cat "The test print to a file \ using %1\$s subsystem can't be initiated\n" "System V" # : Removing the file created for printing # /usr/bin/rm -rf /dev/${TEMP_FILE} >> $LOG_FILE 2>&1 return 0 } # : Create a printer to a file # KLIB_SA_logmsg INFO 5 10 print_server_sa.cat "Creating \ a %1$s print queue printing to a file\n" "System V" /usr/sbin/lpadmin -m standard -T hplaserjet \ -I simple -p $PRINT_QUEUE -v /dev/$TEMP_FILE >> $LOG_FILE 2>&1 (( $? != 0 )) && { # : We are unable to create a print queue. # KLIB_SA_logmsg ERROR 5 11 print_server_sa.cat "The creation of print queue %1\$s \ for %2\$s subsystem failed.\n" "$PRINT_QUEUE" "System V" # : Removing the file created for printing # /usr/bin/rm -rf /dev/${TEMP_FILE} >> $LOG_FILE 2>&1 return 1 } # : Accepting print queue # KLIB_SA_logmsg INFO 5 18 print_server_sa.cat "Accepting print queue %1\$s\n" $PRINT_QUEUE /usr/sbin/accept $PRINT_QUEUE >> $LOG_FILE 2>&1 (( $? != 0 )) && { # : We are unable to accept print queue # KLIB_SA_logmsg ERROR 5 19 print_server_sa.cat "The print queue %1\$s accept \ failed\n" $PRINT_QUEUE # : Cleanup # cleanup return 1 } # : Enable print queue # KLIB_SA_logmsg INFO 5 20 print_server_sa.cat "Enabling print queue %1\$s\n" $PRINT_QUEUE /usr/sysv/bin/enable $PRINT_QUEUE >> $LOG_FILE 2>&1 (( $? != 0 )) && { # : We are unable to enable the print queue # KLIB_SA_logmsg ERROR 5 21 print_server_sa.cat "The print queue %1\$s couldn't \ enabled\n" $PRINT_QUEUE # : Cleanup # cleanup return 1 } # : Test print using System V subsystem # KLIB_SA_logmsg INFO 5 12 print_server_sa.cat "Test print to \ the file using %1\$s print subsystem\n" "System V" /usr/sbin/lptest 5 5 | /usr/bin/lp -d $PRINT_QUEUE -L C >> $LOG_FILE 2>&1 (( $? != 0 )) && { # : We are unable to initate print using System V subsystem # KLIB_SA_logmsg ERROR 5 13 print_server_sa.cat "The print request using %1\$s print \ subsystem failed\n" "System V" # : Cleanup # cleanup return 1 } # : sleeping here for sometime for the print queue to become empty # sleep 5 # : Verify the printing is done or not after counting : the number of lines in the file # KLIB_SA_logmsg INFO 5 14 print_server_sa.cat "The number of lines in the temporary file \ should be greater than 0 after print\n" NUM_LINES=$(/usr/bin/cat /dev/$TEMP_FILE | LC_ALL=C /usr/bin/wc -l 2>/dev/null) NUM_LINES=${NUM_LINES// /} # : if NUM_LINES is greater than 0 : print subsystem is active : else : print subsystem is not active # (( $NUM_LINES > 0 )) && { KLIB_SA_logmsg INFO 3 1 print_server_sa.cat "%1\$s \ print subsystem is active\n" "System V" # : Cleaning up # cleanup return 0 } # : If we are here then System V print subsystem is not active # KLIB_SA_logmsg ERROR 3 2 print_server_sa.cat "%1\$s \ print subsystem is not active\n" "System V" # : Cleaning up # cleanup return 1 } ############################################################################### # Main program procedure. ############################################################################### PROGNAME=$(basename ${0}) PATH="$($(dirname ${0})/../../../utilities/cl_get_path all)" PATH=$PATH:/usr/bin:/etc:/usr/sbin:/usr/ucb:/sbin FPATH_BASE=/usr/es/lib/ksh93 FPATH=$FPATH_BASE/hacmp:$FPATH_BASE/sa:$FPATH_BASE/aix:$FPATH_BASE/aix/odm export PATH FPATH # We need to set this so that we can gather enough details in # /var/hacmp/log/clappmond..monitor.log for debugging. export VERBOSE_LOGGING=${VERBOSE_LOGGING:-"high"} eval export $(cllsparam -n $(clodmget -f nodename HACMPcluster)) if [[ $VERBOSE_LOGGING == 'high' ]] then PS4_TIMER=true set -x version='1.4' fi # : Load the common variables # . /usr/es/sbin/cluster/sa/printServer/sbin/cl_print_server_common_variables LOG_FILE=$(clodmget -q name=$KLIB_HACMPLOG_ENTRY -f value -d "=" HACMPlogs) LOG_FILE=${LOG_FILE//\"/} LOG_FILE="$LOG_FILE/$KLIB_HACMPLOG_ENTRY" # : temporary file name and required print queue name # TEMP_FILE="temp_systemv_$$" PRINT_QUEUE="temp_queue_$$" [[ "$VERBOSE_LOGGING" == "high" ]] && set -x BASENAME=$(basename $0) echo "######################################################" >> $LOG_FILE dspmsg -s 5 print_server_sa.cat 22 "# SYSTEM V PRINT SUBSYSTEM HEALTH MONITOR" >> $LOG_FILE echo "\n######################################################" >> $LOG_FILE # : System V print subsystem health monitoring # systemv_monitor exit $?