寫一個支持cluster suite切換的應用腳本
一個CS的應用程序腳本需要符合LSB標準,需要支持以下幾個參數
start start the service
stop stop the service
restart stop and restart the service if the service is already running, otherwise start the service
try-restart restart the service if the service is already running
reload cause the configuration of the service to be reloaded without actually stopping and restarting the service
force-reload cause the configuration to be reloaded if the service supports this, otherwise restart the service if it is running
status print the current status of the service
你可以在/etc/init.d/下找到一些系統自帶服務的啟動腳本,比如ftp什麼的,一般情況下他們都可以直接使用在CS中
如果你想編寫一個第三方應用程序的腳本,那麼一個帶註釋的例子如下
#!/bin/bash
#
# Copyright Red Hat Inc., 2002
# Copyright Mission Critical Linux, 2000
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING. If not, write to the
# Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
# MA 02139, USA.
#
#
# Author: Gregory P. Myrdal <
[email protected]>
#
#
# This file contains a template that you can use to create a script
# that will start, stop and monitor an application used in a cluster service.
#
#------------------------------------------------------------
# Variable definitions
#------------------------------------------------------------
MYNAME=$(basename $0)
# The clug utility uses the normal logging levels as defined in
# sys/syslog.h. Calls to clulog will use the logging level defined
# for the Service Manager (clusvcmgrd).
LOG_EMERG=0 # system is unusable
LOG_ALERT=1 # action must be taken immediately
LOG_CRIT=2 # critical conditions
LOG_ERR=3 # error conditions
LOG_WARNING=4 # warning conditions
LOG_NOTICE=5 # normal but significant condition
LOG_INFO=6 # informational
LOG_DEBUG=7 # debug-level messages
#------------------------------------------------------------
# Start of execution
#------------------------------------------------------------
if [ $# -ne 2 ]; then
echo "Usage: $0 {start, stop, status} service_name"
exit 1
fi
action=$1 # type of action, i.e. 'start', 'stop' or 'status'
svcName=$2 # name of the service
#
# Record all output into a temp file in case of error
#
exec > /tmp/$MYNAME.$action.log 2>&1
clulog -s $LOG_DEBUG "In $0 with action=$action, svcName=$svcName"
case $action in
'start')
clulog -s $LOG_INFO "Running user start script for service $svcName"
#
# <<< EDIT HERE: Add service start specfic code here >>>
#
;;
'stop')
clulog -s $LOG_INFO "Running user stop script for service $svcName"
#
# <<< EDIT HERE: Add service stop specfic code here >>>
#
;;
'status')
clulog -s $LOG_INFO "Running user status script for service $svcName"
#
# <<< EDIT HERE: Add service status specfic code here >>>
#
;;
*)
clulog -s $LOG_ERR \
"Unknown action '$action' passed to $svcName user script"
exit 1 # return failure
esac
exit 0 # return success
一個不符合lSB標準的腳本將導致,CS不停重起你的應用程序,一個典型的例子就是httpd....oh my God !
詳情見bugzilla
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=151104
希望能拋磚引玉,大家share出自己的腳本作品和實踐中的經驗教訓,共同提高
[ 本帖最後由 fuumax 於 2006-12-31 13:14 編輯 ]
《解決方案》
暈, 這玩意就看實際應用了, 沒有什麼好說的 . 不過想apache, mysql什麼的好像沒有狀態控制. 代碼要加上
status選項. 選項控制可以根據自己具體使用情況, 加以判斷做流程式控制制.. 感覺這些例子沒有什麼用處.
《解決方案》
原帖由 haishen 於 2006-12-31 13:30 發表
暈, 這玩意就看實際應用了, 沒有什麼好說的 . 不過想apache, mysql什麼的好像沒有狀態控制. 代碼要加上
status選項. 選項控制可以根據自己具體使用情況, 加以判斷做流程式控制制.. 感覺這些例子沒有什麼用處.
人家是好心總要支持一下嘛, 讓你這麼折騰沒人願來發貼了, 真是的,,,
《解決方案》
噢 嘿嘿 , 我錯了
鼓勵 鼓勵, 不會讓我一句不著邊的話就打死吧, 也太脆弱了.......