通过命令行启动的nginx,无法使用systemctl 来停止和查看它的状态

    1. #!/bin/bash
    2. [ -f /etc/init.d/functions ] && . /etc/init.d/functions
    3. input=$1
    4. #开始
    5. start(){
    6. /usr/sbin/nginx
    7. }
    8. #停止
    9. stop(){
    10. /usr/sbin/nginx -s stop
    11. }
    12. #重启
    13. restart(){
    14. stop
    15. sleep 1
    16. start
    17. }
    18. #重新加载
    19. reload(){
    20. /usr/sbin/nginx -s reload
    21. }
    22. #状态
    23. status(){
    24. port=`netstat -ntulp|grep [n]ginx|awk -F '[ ]+' 'NR==1{print $4}'`
    25. pid=`ps axu|grep nginx|grep master|awk '{print $2}'`
    26. if [ -n "${port}" -a -n "${pid}" ];then
    27. echo "当前nginx监听端口是: ${port} 长度为:${#port}"
    28. echo "当前nginx pid 是: ${pid} 长度为:${#pid}"
    29. else
    30. echo "nginx未启动"
    31. fi
    32. }
    33. case ${input} in
    34. start)
    35. start
    36. [ $? -eq 0 ]&& action "Nginx Start is" /bin/true || action "Nginx Start is" /bin/false
    37. ;;
    38. stop)
    39. stop
    40. [ $? -eq 0 ]&& action "Nginx Stop is" /bin/true || action "Nginx stop is" /bin/false
    41. ;;
    42. status)
    43. status;;
    44. restart)
    45. restart
    46. [ $? -eq 0 ]&& action "Nginx restart is" /bin/true || action "Nginx restart is" /bin/false
    47. ;;
    48. *)
    49. echo "请输入参数哦|start|stop|status|reload|restart"
    50. esac