程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SyBase數據庫 >> SyBase綜合文章 >> 如何讓Sybase服務在系統啟動時自動啟動?

如何讓Sybase服務在系統啟動時自動啟動?

編輯:SyBase綜合文章

自 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
  需要注意的是:

  • 該腳本並不自動關閉數據庫。在重啟系統或關機時,它只是檢查是否仍有 Sybase 服務在運行,並記錄日志。建議 DBA 在重啟或關閉 OS 之前,通過 isql,手工 shutdown 數據庫服務。
  • 該腳本假定系統中不存在僅大小寫有差異的服務名,如 SYBASE和 Sybase。如果系統中確實存在,則此腳本的行為不可預知。
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved