前面写过几遍不同类型的生产环境管理命令
今天这里整理给main函数添加参数的方法
#!/bin/bash
Tag="test"
MainClass="com.yokead.Application"
Lib="/test/admin/lib/"
Log="/test/admin/run.log"
echo $Tag
RETVAL="0"
# See how we were called.
function start() {
echo $Log
if [ ! -f $Log ]; then
touch $Log
fi
nohup java -Dappliction=$Tag -Djava.ext.dirs=$Lib":${JAVA_HOME}/jre/lib/ext" $MainClass $arg > $Log 2>&1 &
tailf $Log
}
function stop() {
pid=$(ps -ef | grep -v 'grep' | egrep $Tag| awk '{printf $2 " "}')
if [ "$pid" != "" ]; then
echo -n "boot ( pid $pid) is running"
echo
echo -n $"Shutting down boot: "
pid=$(ps -ef | grep -v 'grep' | egrep $Tag| awk '{printf $2 " "}')
if [ "$pid" != "" ]; then
echo "kill boot process"
kill -9 "$pid"
fi
else
echo "boot is stopped"
fi
status
}
function status()
{
pid=$(ps -ef | grep -v 'grep' | egrep $Tag| awk '{printf $2 " "}')
#echo "$pid"
if [ "$pid" != "" ]; then
echo "boot is running,pid is $pid"
else
echo "boot is stopped"
fi
}
function usage()
{
echo "Usage: $0 {start|stop|restart|status}"
RETVAL="2"
}
# See how we were called.
RETVAL="0"
arg="$2"
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
*)
usage
;;
esac
exit $RETVAL
使用方法是:
./test.sh start test
这样start 后面跟着参数值
这样大家配合前面几个方法,可以随意组合出更高级的管理了,如果在使用过程中有疑问或者更好的建议欢迎随机交流