Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1416763
  • 博文数量: 264
  • 博客积分: 5810
  • 博客等级: 大校
  • 技术积分: 3528
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-13 17:15
文章分类

全部博文(264)

文章存档

2011年(264)

分类: LINUX

2011-05-29 07:53:38

  1. #!/bin/sh
  2. # 将脚本保存为/etc/rc.d/init.d/nginxd,便可以使用service命令启动、停止、重启nginx服务。service nginxd restart
  3. # 启动nginx 命令./nginxd start 关闭./nginxd stop 重启 ./nginxd restart
  4. # source function library
  5. . /etc/rc.d/init.d/functions

  6. # Source networking configuration.
  7. . /etc/sysconfig/network

  8. # Check that networking is up.
  9. [ ${NETWORKING} = "no" ] && exit 0

  10. RETVAL=0
  11. prog="nginx"

  12. nginxDir=/usr/local/nginx #视安装路径而作修改
  13. nginxd=$nginxDir/sbin/nginx
  14. nginxConf=$nginxDir/conf/nginx.conf
  15. nginxPid=$nginxDir/nginx.pid

  16. start()
  17. {
  18.         if [[ -e $nginxPid ]]; then
  19.                 echo "$prog already running..."
  20.                 exit 1
  21.         else
  22.                 echo -n $"Starting $prog:"
  23.                 daemon $nginxd -c $nginxConf
  24.                 RETVAL=$?
  25.                 echo
  26.                 [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
  27.                 return $RETVAL
  28.         fi
  29. }

  30. stop()
  31. {
  32.         echo -n $"Stopping $prog:"
  33.         killproc $nginxd

  34.         RETVAL=$?
  35.         echo
  36.         [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx $nginxPid
  37. }

  38. reload()
  39. {
  40.         echo -n $"Reloading $prog:"
  41.         killproc $nginxd -HUP
  42.         RETVAL=$?
  43.         echo
  44. }

  45. case "$1" in
  46.         start)
  47.                 start
  48.                 ;;
  49.         stop)
  50.                 stop
  51.                 ;;
  52.         restart)
  53.                 stop
  54.                 start
  55.                 ;;
  56.         reload)
  57.                 reload
  58.                 ;;
  59.         status)
  60.                 status $prog
  61.                 RETVAL=$?
  62.                 ;;
  63.         *)
  64.                 echo $"Usage: $0 {start|stop|restart|reload|status}"
  65.                 RETVAL=1
  66. esac
  67. exit $RETVAL
阅读(960) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~