以下是一個(gè)resin啟動(dòng)腳本,其中可以學(xué)到很多bash shell的知識(shí)點(diǎn)
#!/bin/sh // bash shell腳本
#
# Linux startup script for Resin //#注釋
# chkconfig: 345 85 15
# description: Resin is a Java Web server.
# processname: wrapper.pl
#
# To install, configure this file as needed and copy init.resin
# to /etc/rc.d/init.d as resin. Then use "# /sbin/chkconfig resin reset"
#
JAVA_HOME=/usr/local/java/jdk // =號(hào)賦值
RESIN_HOME=/usr/local/resin
export JAVA_HOME RESIN_HOME // export 定義全局變量
JAVA=$JAVA_HOME/bin/java // $ 代表變量
#
# If you want to start the entire Resin process as a different user,
# set this to the user name. If you need to bind to a protected port,
# e.g. port 80, you can't use USER, but will need to use bin/resin.
#
USER=
#
# Set to the server id to start
#
#SERVER="-server app-a"
#
ARGS="-resin-home $RESIN_HOME $SERVER"
if test -r /lib/lsb/init-functions; then // 判斷語句 test -r /lib/lsb/init-functions 條件文件存在并可讀
. /lib/lsb/init-functions // . 代表源 同source /lib/lsb/init-functions
else //如果不符合上面的條件
log_daemon_msg () { //函數(shù)
if [ -z "$1" ]; then // -z "$1" 變量$1長(zhǎng)度為0 // $1 腳本執(zhí)行時(shí)傳過來的第一個(gè)參數(shù)
return 1 //返回
fi
if [ -z "$2" ]; then
echo -n "$1:" // -n 參數(shù) 輸出不換行
return
fi
echo -n "$1: $2"
}
log_end_msg () {
[ -z "$1" ] && return 1 // [ -z "$1" ]為真,執(zhí)行 return 1
if [ $1 -eq 0 ]; then //比較,-eq等于
echo " ."
else
echo " failed!"
fi
return $1
}
fi
case "$1" in //case 選擇語句
start) //腳本第一個(gè)參數(shù)為start
log_daemon_msg "Starting resin" //調(diào)用函數(shù),傳遞參數(shù)
if test -n "$USER"; then //條件:變量USER長(zhǎng)度不為0
su $USER -c "$JAVA -jar $RESIN_HOME/lib/resin.jar $ARGS start" 1>/dev/null 2>/dev/null //su 以其它用戶執(zhí)行 -c執(zhí)行命令后恢復(fù)身份
else
$JAVA -jar $RESIN_HOME/lib/resin.jar $ARGS start 1>/dev/null 2>/dev/null //1>dev/null 執(zhí)行正常信息輸出到空文件 2>錯(cuò)誤信息
fi
log_end_msg $? // $? 上一條命令執(zhí)行的結(jié)果 0表示成功,更多請(qǐng)查看其它文章
;;
stop)
log_daemon_msg "Stopping resin"
if test -n "$USER"; then
su $USER -c "$JAVA -jar $RESIN_HOME/lib/resin.jar $ARGS stop" 1>/dev/null 2>/dev/null
else
$JAVA -jar $RESIN_HOME/lib/resin.jar $ARGS stop 1>/dev/null 2>/dev/null
fi
log_end_msg $?
;;
restart)
$0 stop //$0 本腳本名
$0 start
;;
*) //除start stop restart外
echo "Usage: $0 {start|stop|restart}"
exit 1 //1表示有錯(cuò)誤
esac
exit 0 //0表示沒有錯(cuò)誤
文章題目:從一個(gè)linux腳本中學(xué)習(xí)bashshell-創(chuàng)新互聯(lián)
當(dāng)前鏈接:
http://weahome.cn/article/dsigjs.html