加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl版nginx启动daemon

发布时间:2020-12-16 00:29:22 所属栏目:大数据 来源:网络整理
导读:好长一段时间本人的博客都未更新了,新年向大家献上第一份博文。网上关于nginx的启动脚本大都是shell版的,我尝试着用perl重写了一下,不足之处,恳请指正。 code: #!/bin/env?perl? #? #?chkconfig:???-?85?15? #?description:?nginx?is?a?web?server? #?pr

好长一段时间本人的博客都未更新了,新年向大家献上第一份博文。网上关于nginx的启动脚本大都是shell版的,我尝试着用perl重写了一下,不足之处,恳请指正。

code:

 
 
  1. #!/bin/env?perl?
  2. #?
  3. #?chkconfig:???-?85?15?
  4. #?description:?nginx?is?a?web?server?
  5. #?progname:????nginx?
  6. #?config_file:?/opt/nginx/conf/nginx.conf?
  7. #?pid_file:????/opt/nginx/logs/nginx.pid?
  8. #?author:??????Henry?He?on?2012/01/09?
  9. ?
  10. use?strict;?
  11. use?File::Basename?qw/basename/;?
  12. use?Term::ANSIColor?qw(:constants);?
  13. ?
  14. #?Global?options?for?my?color?
  15. $Term::ANSIColor::AUTORESET?=?1;?
  16. ?
  17. my?$base_dir?=?"/opt/nginx";?
  18. my?$prog?=?`basename?$base_dir`;?
  19. chomp?$prog;?
  20. ?
  21. if?(!?-f?"$base_dir/conf/nginx.conf")?{?
  22. ???&errorexit("no?nginx?config?file");?
  23. }?
  24. ?
  25. if?(!?-x?"$base_dir/sbin/nginx")?{?
  26. ???&errorexit("can't?excute?nginx?binary?file");?
  27. }?
  28. ?
  29. if?(@ARGV?!=?0)?{?
  30. ?
  31. ????for?my?$args?(@ARGV)?{?
  32. ?
  33. ????????if?($args?=~?/(bstartb)+/)?{?
  34. ????????????print?BOLD?GREEN?"Starting?nginx?now?...";?
  35. ????????????system?"$base_dir/sbin/nginx?-c?$base_dir/conf/nginx.conf";?
  36. ????????????system?"touch?/var/lock/subsys/$prog";?
  37. ????????????printf?"%-sn","[OK]";?
  38. ????????}?
  39. ????????elsif?($args?=~?/(bstopb)+/)?{?
  40. ????????????print?BOLD?GREEN?"Stopping?nginx?now?...";?
  41. ????????????system?"killall?-s?QUIT?$prog";?
  42. ????????????unlink?"$base_dir/logs/nginx.pid";?
  43. ????????????unlink?"/var/lock/subsys/$prog";?
  44. ????????????printf?"%-sn","[OK]";?
  45. ??????}?
  46. ???????elsif?($args?=~?/(breloadb)+/)?{?
  47. ????????????print?BOLD?GREEN?"Reload?nginx?now";?
  48. ????????????system?"killall?-s?HUP?$prog";?
  49. ????????????printf?"%-sn","[OK]";?
  50. ????????}?
  51. ????????elsif?($args?=~?/(bstatusb)+/)?{?
  52. ?
  53. ????????????if?(open?FILE,"<","$base_dir/logs/nginx.pid")?{?
  54. ????????????????chomp(my?$pid?=?<FILE>);?
  55. ????????????????close?FILE;?
  56. ????????????????printf?"%sn","$prog?(pid?$pid?is?running)";?
  57. ????????????}?
  58. ?
  59. ????????}?
  60. ????????else?{?
  61. ????????????usage();?
  62. ????????????exit?1;?
  63. ????????}?
  64. ?
  65. ????}?
  66. ?
  67. }?else?{?
  68. ????????usage();?
  69. }?
  70. ?
  71. sub?errorexit?{?
  72. ????printf?"ERROR:?%s",@_;?
  73. ????printf?"n";?
  74. ????exit?0;?
  75. }?
  76. ?
  77. sub?usage?{?
  78. ????printf?"USAGE:??%-10sn","/etc/init.d/nginx??{start|stop|status|reload}";?
  79. }?

将此脚本命名为nginx并拷贝到/etc/init.d/目录下

 
 
  1. #?cp?nginx?/etc/init.d/nginx?
  2. #?chkconfig?--add?nginx?
  3. #?chkconfig?nginx?on?
  4. #?/etc/init.d/nginx?
  5. USAGE:??/etc/init.d/nginx??{start|stop|status|reload}?
  6. #?#?/etc/init.d/nginx?start?
  7. Starting?nginx?now?...[OK]?
  8. ......................................................?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读