#/bin/bash
pid=`ps -ef | grep 'testDemo' | grep -v grep |awk '{print $2}'`
case $1 in
start)
nohup java -j testDemo.jar > log.txt 2>&1 &
echo "testDemo is RUNNING"
;;
stop)
echo "$pid is killed"
kill -9 $pid
;;
restart)
stop;
start;
;;
status)
if [ ! $pid ]; then
echo "testDemo NOT run"
else
echo "testDemo is RUNNING, pid-- $pid"
fi
;;
*)
echo "usage: $0 {start|stop|restart|status}"
exit -1
;;
esac
可以参考这个demo