自 12.5.1 開始,Sybase 不再提供啟動腳本,但我們可以自己寫一個簡單的腳本。
將下面的代碼另存為 /etc/init.d/sybase ,並改變文件屬性為 755 (chmod 755 /etc/init.d/Sybase )。
注意 Sybase 安裝目錄和 Sybase 用戶的修改。
#!/bin/bash # # service scripts for Sybase ASE # # Created by Flybean # 2006.02.19 # Modify the following directorIEs and user to yours SYB_HOME=/opt/sybase SYB_USER=sybase LOGFILE=/var/log/sybase function init(){ if [ -r $SYB_HOME/SYBASE.sh ]; then . $SYB_HOME/SYBASE.sh else log "ERRO" "Sybase env is not set." exit 1 fi if [ ! -w $LOGFILE ]; then touch $LOGFILE chmod 666 $LOGFILE fi } function log(){ local logType=$1 shift local s=`date +"[%Y-%m-%e %T %a] [$logType] $@"` echo $s echo $s >> $LOGFILE } init DIR=$SYBASE/$SYBASE_ASE/install STARTCMD=$DIR/startserver STATUSCMD=$DIR/showserver RSERVICES="" function getRunningServices(){ local lines=`$STATUSCMD | grep $DIR | tr "[a-z]" "[A-Z]" | sed -e 's/.*-S//' -e 's/ .*//'` RSERVICES=""; local retval=0 local line for line in $lines; do RSERVICES="$RSERVICES $line " retval=1 done return $retval } function isServiceExist(){ if [ -f $DIR/RUN_$1 ]; then return 1; else return 0; fi } function isServiceRunning(){ getRunningServices local service=" $1 " local rs=`echo "$RSERVICES" | grep -iF "$service"` local retval=1 if [ "$rs" = "" ]; then retval=0 fi return $retval } function startService(){ isServiceRunning $1 if [ $? = 0 ]; then echo -n "Start Sybase Service $1 : " su - $SYB_USER -c "$STARTCMD -f $DIR/RUN_$1 >/dev/null 2>&1" for (( times = 0; times < 10; times ++ )); do isServiceRunning $1 if [ $? = 0 ]; then echo "failed" log "ERRO" "Service $1 could not startup. Check log!" return 1 else sleep 2s fi done log "INFO" "Service $1 is starup." return 0 else log "WARN" "Service $1 was startup." return 2 fi } getRunningServices case "$1" in start) for i in $DIR/RUN_*; do service=${i##*/RUN_} startService $service done unset i ;; startservice) isServiceExist $2 if [ $? = 0 ]; then log "WARN" "Service <$2> does not exist." else startService $2 fi ;; stop) if [ $? = 0 ]; then log "INFO" "All Sybase Service had stoped." else runlevel=`/sbin/runlevel | sed -e 's/.*[^0-9]//'` case "$runlevel" in "0"|"6") log "WARN" "Sybase Service <$RSERVICES> are still running while shutdown. You should shutdown these services first." ;; *) echo "It's not supported to stop services. Please use isql to shutdown services." esac fi ;; status) if [ $? = 0 ]; then echo "No Sybase Service running now." else echo "Running services: <$RSERVICES>" fi ;; all) for i in $DIR/RUN_*; do echo "Service: ${i##*/RUN_}" done unset i ;; *) echo $"Usage: $0 {start|stop|status|startservice name|all}" esac unset DIR unset SYB_HOME unset SYB_USER unset STARTCMD unset STATUSCMD exit
######################################
SYB_HOME=/opt/Sybase
SYB_USER=Sybase
然後為運行級別建立服務連接,通常是運行級別 3 和 5。 ln -s /etc/init.d/sybase /etc/rc.d/rc3.d/S99Sybase
ln -s /etc/init.d/sybase /etc/rc.d/rc5.d/S99sybase ln -s /etc/init.d/sybase /etc/rc.d/rc0.d/K01Sybase
ln -s /etc/init.d/sybase /etc/rc.d/rc6.d/K01Sybase
該腳本所記錄的日志文件為:/var/log/Sybase
需要注意的是: