有关linux启动脚本的浅析:
1、参数脚本。
#应用id,应用的唯一标识。
APP_NAME=APP_01
APP_DIR=../
APP_BIN=${APP_DIR}/bin
APP_LIB=${APP_DIR}/lib
APP_LOG=${APP_DIR}/log
APP_SCRIPT=${APP_DIR}/script
2、路径脚本。
. para
CLASSPATH=
CLASSPATH=$CLASSPATH:${APP_BIN}
for jarfile in `ls -1 ../lib/*.jar`
do
CLASSPATH="$CLASSPATH:$jarfile"
done
#export CLASSPATH
3、启动脚本。
#! /bin/bash
clear
. para
. class_path
#编码方式
export LANG=zh_CN.GB18030
echo $LANG
cd ${APP_BIN}
echo "${APP_NAME} starting ..."
sleep 1
nohup java -Xms256m -Xmx512m -Xss256k -Dflag=${PLATFORM2_NAME} -XX:PermSize=128m -XX:MaxPermSize=256m -Djava.security.policy="policy.txt" -Djava.rmi.server.codebase=file://${PLATFORM2_BIN}/ -cp ${CLASSPATH} com.umpay.app.Start >${APP_LOG}/console.out &
cd ${APP_SCRIPT}
#sleep 1
tail -50f ${APP_LOG}/console.out
4、停止脚本。
4.1)、方式一
#! /bin/bash
sleep 1
ps -ef|grep Dflag=${APP_NAME}|grep -v grep|grep -v tail|awk 'BEGIN{printf "kill "}{printf "%s ", $2}'|bash
echo "${APP_NAME} stopped!
4.2)、方式二
#! /bin/bash
. para
c=0
while [ $c -eq 0 ]
do
echo "do"
result=`ps -ef|grep "Dflag=${APP_NAME}"|grep -v grep`
if [ -n "${result}" ]
then
echo $result
ps -ef|grep Dflag=${APP_NAME}|grep -v grep|grep -v tail|awk 'BEGIN{printf "kill "}{printf "%s ", $2}'|bash
result=`ps -ef|grep "Dflag=${APP_NAME}"|grep -v grep`
sleep 2
else
c=1
echo "else"
fi
done
echo "结束"
5、重启脚本。
#! /bin/bash
./unserv.sh
sleep 5
./start.sh
6、状态脚本。
. para
result=`ps -ef|grep "Dflag=${APP_NAME}"|grep -v grep`
if [ -n "${result}" ]
then
echo "${APP_NAME} is running."
else
echo "${APP_NAME} not found..."
fi
7、日志脚本。
#! /bin/bash
clear
. para
sleep 1
tail -30f ${APP_NAME}/console.out