呵呵呵,想起了一个以前写的shell脚本,启动和关闭线程(myshell.sh)。
会自动生成server.pid记录当前线程的PID.
日志文件logger.info形式的日志记录进了Server.log ,当然也可以去掉写入Server.log改用自己的Log4j.
年代久远 ,记录另一个启动脚本,centos下可用:
CLASS_PATH=dayemail.jar
CLASS_PATH=$CLASS_PATH:lib/activation.jar
CLASS_PATH=$CLASS_PATH:lib/classes12.jar
CLASS_PATH=$CLASS_PATH:lib/c3p0-0.9.1.2.jar
CLASS_PATH=$CLASS_PATH:lib/commons-email-1.2.jar
CLASS_PATH=$CLASS_PATH:lib/dom4j-1.6.jar
CLASS_PATH=$CLASS_PATH:lib/jaxen-1.1.1.jar
CLASS_PATH=$CLASS_PATH:lib/jxl.jar
CLASS_PATH=$CLASS_PATH:lib/log4j-1.2.16.jar
CLASS_PATH=$CLASS_PATH:lib/mail.jar
SERVER=/qzpt/mydayemail
cd $SERVER
case "$1" in
start)
nohup java -Dfile.encoding=UTF8 -Xms64M -Xmx256M -cp $CLASS_PATH com.trendsnet.myemail.EmailShell > $SERVER/server.log 2>&1 &
echo $! > $SERVER/server.pid
;;
stop)
kill `cat $SERVER/server.pid`
rm -rf $SERVER/server.pid
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "Usage: myshell.sh {start|stop|restart}"
;;
esac
exit 0
会自动生成server.pid记录当前线程的PID.
日志文件logger.info形式的日志记录进了Server.log ,当然也可以去掉写入Server.log改用自己的Log4j.
年代久远 ,记录另一个启动脚本,centos下可用:
CLASS_PATH=
# Append jars to CLASS_PATH
if [ -d lib ]; then
for i in lib/*.jar; do
CLASS_PATH="$CLASS_PATH":"$i"
done
fi
#启动命令
MSTART="java -Dfile.encoding=UTF8 -Xms128M -Xmx512M -cp $CLASS_PATH com.data.StartShell"
#停止
if [ "$1" = "stop" ]
then
#kill all Pid
pidlist=`ps -ef|grep com.data.check.StartShell | grep -v "grep"|awk '{print $2}'`
if [ "$pidlist" = "" ]
then
echo "No Service Running!"
else
for pid in ${pidlist}
do
kill -9 $pid
done
echo "Service Stop Success!"
fi
fi
#启动
if [ "$1" = "start" ]
then
pidlist=`ps -ef|grep com.data.check.StartShell | grep -v "grep"|awk '{print $2}'`
if [ "$pidlist" = "" ]
then
nohup $MSTART > /dev/null 2>&1 &
pidlist=`ps -ef|grep com.data.check.StartShell | grep -v "grep"|awk '{print $2}'`
if [ "$pidlist" = "" ]
then
echo "Service Start Failed!"
else
echo "Service Start Success!"
fi
else
echo "Service Exists!"
fi
fi
#检查是否启动
if [ "$1" = "check" ]
then
pidlist=`ps -ef|grep com.data.check.StartShell | grep -v "grep"|awk '{print $2}'`
if [ "$pidlist" = "" ]
then
echo "Service Not Exists!"
else
echo "Service Exists!"
fi
fi
#监控,如果不存在,自动启动
if [ "$1" = "monitor" ]
then
while [ 1 ] ;do
pidlist=`ps -ef|grep com.data.check.StartShell | grep -v "grep"|awk '{print $2}'`
if [ "$pidlist" = "" ]
then
nohup $MSTART > /dev/null 2>&1 &
fi
sleep 10;
done
fi
if [ -z "$1" ]
then
echo "Parm must be: [start|stop|check|monitor]"
fi