linux 简易启动脚本

时间:2022-04-24
本文章向大家介绍linux 简易启动脚本,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
#/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