#!/bin/bash
start(){
IAS_HOME=$IAS_HOME
APP_NAME=project-1
WAIT_TIME=5
echo "IAS_HOME:"${IAS_HOME}
IAS_ID=$(ps -ef|grep $APP_NAME|grep 'jar'|grep -v 'grep'|head -1|awk '{print $2}') #查找PID
if [ -n "$IAS_ID" ]; then #判断pid是否已经存在
echo "[$APP_NAME] is already running with process id: $IAS_ID"
exit 0
fi
echo "[${APP_NAME}] will be start"
cd ${IAS_HOME}
#nohup java -jar *.jar &
nohup java -Dcom.sun.management.jmxremote.port=9401 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname="10.10.2.231" -Xms100M -Xmx1024M -XX:PermSize=20M -XX:MaxPermSize=1048M -XX:MaxDirectMemorySize=64M -jar *.jar & #不挂断运行程序
sleep ${WAIT_TIME}
IAS_ID=$(ps -ef|grep $APP_NAME|grep 'jar'|grep -v 'grep'|head -1|awk '{print $2}')
if [ -n "$IAS_ID" ]; then
echo "[${APP_NAME}] is running with process id: $IAS_ID"
exit 0
else
echo "[${APP_NAME}] start fail"
exit 1
fi
}
stop(){
IAS_HOME=$IAS_HOME
APP_NAME=project-1
WAIT_TIME=5
echo "IAS_HOME:"${IAS_HOME}
IAS_ID=$(ps -ef|grep $APP_NAME|grep 'jar'|grep -v 'grep'|head -1|awk '{print $2}')
if [ -z "$IAS_ID" ]; then
echo "[${APP_NAME}] has bean stop"
exit 0
fi
echo "[${APP_NAME}] will be stop"
kill -9 $IAS_ID
sleep ${WAIT_TIME}
IAS_ID=$(ps -ef|grep $APP_NAME|grep 'jar'|grep -v 'grep'|head -1|awk '{print $2}')
if [ -z "$IAS_ID" ]; then #判断pid是否存在
echo "[${APP_NAME}] stop success"
exit 0
else
echo "[${APP_NAME}] stop fail"
exit 1
fi
}
status(){
IAS_HOME=$IAS_HOME
APP_NAME=project-1
WAIT_TIME=5
echo "IAS_HOME:"${IAS_HOME}
IAS_ID=$(ps -ef|grep $APP_NAME|grep 'jar'|grep -v 'grep'|head -1|awk '{print $2}')
if [ -n "$IAS_ID" ]; then
echo "[${APP_NAME}] is running with process id: $IAS_ID"
exit 0
else
echo "[${APP_NAME}] is not running"
exit 1
fi
}
case "$1" in
start)
echo "start project"
start
;;
stop)
echo "stop project"
stop
;;
status)
status
;;
restart)
echo "restart project"
$0 stop
sleep 1
$0 start
;;
*)
printf 'Usage: %s {start|stop|status|restart}\n' "$prog"
exit 1
;;
esac
start(){
IAS_HOME=$IAS_HOME
APP_NAME=project-1
WAIT_TIME=5
echo "IAS_HOME:"${IAS_HOME}
IAS_ID=$(ps -ef|grep $APP_NAME|grep 'jar'|grep -v 'grep'|head -1|awk '{print $2}') #查找PID
if [ -n "$IAS_ID" ]; then #判断pid是否已经存在
echo "[$APP_NAME] is already running with process id: $IAS_ID"
exit 0
fi
echo "[${APP_NAME}] will be start"
cd ${IAS_HOME}
#nohup java -jar *.jar &
nohup java -Dcom.sun.management.jmxremote.port=9401 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname="10.10.2.231" -Xms100M -Xmx1024M -XX:PermSize=20M -XX:MaxPermSize=1048M -XX:MaxDirectMemorySize=64M -jar *.jar & #不挂断运行程序
sleep ${WAIT_TIME}
IAS_ID=$(ps -ef|grep $APP_NAME|grep 'jar'|grep -v 'grep'|head -1|awk '{print $2}')
if [ -n "$IAS_ID" ]; then
echo "[${APP_NAME}] is running with process id: $IAS_ID"
exit 0
else
echo "[${APP_NAME}] start fail"
exit 1
fi
}
stop(){
IAS_HOME=$IAS_HOME
APP_NAME=project-1
WAIT_TIME=5
echo "IAS_HOME:"${IAS_HOME}
IAS_ID=$(ps -ef|grep $APP_NAME|grep 'jar'|grep -v 'grep'|head -1|awk '{print $2}')
if [ -z "$IAS_ID" ]; then
echo "[${APP_NAME}] has bean stop"
exit 0
fi
echo "[${APP_NAME}] will be stop"
kill -9 $IAS_ID
sleep ${WAIT_TIME}
IAS_ID=$(ps -ef|grep $APP_NAME|grep 'jar'|grep -v 'grep'|head -1|awk '{print $2}')
if [ -z "$IAS_ID" ]; then #判断pid是否存在
echo "[${APP_NAME}] stop success"
exit 0
else
echo "[${APP_NAME}] stop fail"
exit 1
fi
}
status(){
IAS_HOME=$IAS_HOME
APP_NAME=project-1
WAIT_TIME=5
echo "IAS_HOME:"${IAS_HOME}
IAS_ID=$(ps -ef|grep $APP_NAME|grep 'jar'|grep -v 'grep'|head -1|awk '{print $2}')
if [ -n "$IAS_ID" ]; then
echo "[${APP_NAME}] is running with process id: $IAS_ID"
exit 0
else
echo "[${APP_NAME}] is not running"
exit 1
fi
}
case "$1" in
start)
echo "start project"
start
;;
stop)
echo "stop project"
stop
;;
status)
status
;;
restart)
echo "restart project"
$0 stop
sleep 1
$0 start
;;
*)
printf 'Usage: %s {start|stop|status|restart}\n' "$prog"
exit 1
;;
esac