この項では、スクリプト・エージェントを使用するサード・パーティ製アプリケーションの例を示します。
例B-1に、Apache Webサーバーをフェイルオーバーするアクション・スクリプトを示します。
例B-1 Apacheアクション・スクリプト
#!/bin/sh HTTPDCONFLOCATION=/etc/httpd/conf/httpd.conf WEBPAGECHECK=http://<MyVIP>:80/icons/apache_pb.gif case $1 in 'start') /usr/sbin/apachectl -k start -f $HTTPDCONFLOCATION RET=$? ;; sleep(10) ;; 'stop') /usr/sbin/apachectl -k stop RET=$? ;; 'clean') /usr/sbin/apachectl -k stop RET=$? ;; 'check') /usr/bin/wget -q --delete-after $WEBPAGECHECK RET=$? ;; *) RET=0 ;; esac # 0: success; 1 : error if [ $RET -eq 0 ]; then exit 0 else exit 1 fi
例B-2に、xclockスクリプトを示します。このスクリプトは、すべてのLinuxおよびUNIXプラットフォームでデフォルト・バイナリとして利用できるxclock
を使用した簡単なアクション・スクリプトです。
例B-2 xclockアクション・スクリプト
#!/bin/bash # start/stop/check script for xclock example # To test this change BIN_DIR to the directory where xclock is based # and set the DISPLAY variable to a server within your network. BIN_DIR=/usr/X11R6/bin LOG_DIR=/tmp BIN_NAME=xclock DISPLAY=yourhost.domain.com:0.0 export DISPLAY exit_code=0 if [ ! -d $BIN_DIR ] then echo "start failed" exit 2 fi PID1=`ps -ef | grep $BIN_NAME | grep -v grep | grep -v xclock_app | awk '{ print $2 }'` case $1 in 'start') if [ "$PID1" != "" ] then status_p1="running" else if [ -x $BIN_DIR/$BIN_NAME ] then umask 002 ${BIN_DIR}/${BIN_NAME} & 2>${LOG_DIR}/${BIN_NAME}.log status_p1="started" else echo `basename $0`": $BIN_NAME: Executable not found" exit_code=1 fi fi echo "$BIN_NAME: $status_p1" exit $exit_code ;; 'stop') if [ "${PID1}" != "" ] then kill -9 ${PID1} && echo "$BIN_NAME daemon killed" else echo "$BIN_NAME: no running Process!" fi exit $exit_code ;; 'check') if [ "$PID1" != "" ] then echo "running" exit 0 else echo "not running" exit 1 fi ;;*) echo "Usage: "`basename $0`" {start|stop|check}" ;; esac
例B-3に、ファイルを監視するエージェントのシェル・スクリプトの例を示します。エージェントは、起動するとファイル(属性を使用して指定されるファイル)を作成し、停止するとファイルを削除します。CHECKアクションは、ファイルが存在するかどうかを単にチェックするものです。接頭辞_CRS_
を持つ変数は、環境のスクリプトに指定する属性値です。
例B-3 アクション・スクリプトの例
#!/bin/sh TOUCH=/bin/touch RM=/bin/rm PATH_NAME=/tmp/$_CRS_NAME # # These messages go into the CRSD agent log file. echo " ******* `date` ********** " echo "Action script '$_CRS_ACTION_SCRIPT' for resource[$_CRS_NAME] called for action $1" # case "$1" in 'start') echo "START entry point has been called.." echo "Creating the file: $PATH_NAME" $TOUCH $PATH_NAME exit 0 ;; 'stop') echo "STOP entry point has been called.." echo "Deleting the file: $PATH_NAME" $RM $PATH_NAME exit 0 ;; 'check') echo "CHECK entry point has been called.." if [ -e $PATH_NAME ]; then echo "Check -- SUCCESS" exit 0 else echo "Check -- FAILED" exit 1 fi ;; 'clean') echo "CLEAN entry point has been called.." echo "Deleting the file: $PATH_NAME" $RM -f $PATH_NAME exit 0 ;; esac