往事依依,随风而行。淡忘过去的一切,在风中迎接新的希望。

linux下的nginx的简单管理脚本

闲着没事写了个nginx的脚本 使nginx的日常维护变得简单一些

改好以下变量就可以了 (我是按照张宴老大那篇教程位置写的)

nginx_path="/usr/local/webserver/nginx/sbin/nginx" //nginx执行文件位置
nginx_pid="/usr/local/webserver/nginx/nginx.pid"//nginx pid文件位置
nginx_conf="/usr/local/webserver/nginx/conf/nginx.conf" //nginx 配置文件的位置

把它扔到/bin 里面 我起名叫www  最后 chmod +x /bin/www 就ok了

支持一下命令

start  启动
stop   停止
restart   重启
 kill  停止失败的时候 直接杀掉
check   检查配置文件
edit  更改配置文件

其他命令或者不打 显示nginx的版本

shell代码
  1. #!/bin/sh   
  2. nginx_path="/usr/local/webserver/nginx/sbin/nginx"  
  3. nginx_pid="/usr/local/webserver/nginx/nginx.pid"  
  4. nginx_conf="/usr/local/webserver/nginx/conf/nginx.conf"  
  5.   
  6. function_check_config()   
  7. {   
  8.   ${nginx_path} -t   
  9. }   
  10.   
  11. function_kill_nginx()   
  12. {   
  13.   kill -9 $(ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print $2}')   
  14. }   
  15.   
  16. function_restart_nginx()   
  17. {   
  18. kill -HUP `cat ${nginx_pid}`   
  19. }   
  20.   
  21. function_stop_nginx()   
  22. {   
  23.   ${nginx_path} -s stop   
  24. }   
  25.   
  26. function_start_nginx()   
  27. {   
  28.   ${nginx_path} &   
  29. }   
  30.   
  31. function_edit_nginx()   
  32. {   
  33.   vi ${nginx_conf}   
  34. }   
  35.   
  36.   
  37. if [ "$1" = "start" ]; then     
  38.     function_start_nginx     
  39. elif [ "$1" = "stop" ]; then     
  40.     function_stop_nginx     
  41. elif [ "$1" = "restart" ]; then     
  42.     function_restart_nginx    
  43. elif [ "$1" = "kill" ]; then     
  44.     function_kill_nginx     
  45. elif [ "$1" = "check" ]; then  
  46.     function_check_config     
  47. elif [ "$1" = "edit" ]; then  
  48.     function_edit_config    
  49. else    
  50.     ${nginx_path} -v   
  51. fi    

Tags: nginx, lemp, shell, linux

« 上一篇 | 下一篇 »

发表评论

评论内容 (必填):