1. #!/bin/bash
    2. app='netty-server-1.0.0.jar'
    3. args=''
    4. cmd=$1
    5. pid=`ps -ef|grep java|grep $app|awk '{print $2}'`
    6. startup(){
    7. nohup java -jar $args $app &
    8. tail -f nohup.out
    9. }
    10. if [ ! $cmd ]; then
    11. echo "Please specify args 'start|restart|stop'"
    12. exit
    13. fi
    14. if [ $cmd == 'start' ]; then
    15. if [ ! $pid ]; then
    16. startup
    17. else
    18. echo "$app is running! pid=$pid"
    19. fi
    20. fi
    21. if [ $cmd == 'restart' ]; then
    22. if [ $pid ]
    23. then
    24. echo "$pid will be killed after 3 seconds!"
    25. sleep 3
    26. kill -9 $pid
    27. fi
    28. startup
    29. fi
    30. if [ $cmd == 'stop' ]; then
    31. if [ $pid ]; then
    32. echo "$pid will be killed after 3 seconds!"
    33. sleep 3
    34. kill -9 $pid
    35. fi
    36. echo "$app is stopped"
    37. fi
    1. app args改成对应项目的配置
    2. 然后执行chmod +x server.sh添加运行权限
    3. 执行./server.sh start或者./server.sh restart即可启动项目
    4. 执行./server.sh stop停止项目运行