zoukankan      html  css  js  c++  java
  • centos6可用的Apache管理脚本

      1 #!/bin/bash
      2 #
      3 # httpd Startup script for the Apache HTTP Server
      4 #
      5 # chkconfig: - 85 15
      6 # description: The Apache HTTP Server is an efficient and extensible 
      7 # server implementing the current HTTP standards.
      8 # processname: httpd
      9 # config: /etc/httpd/conf/httpd.conf
     10 # config: /etc/sysconfig/httpd
     11 # pidfile: /var/run/httpd/httpd.pid
     12 #
     13 ### BEGIN INIT INFO
     14 # Provides: httpd
     15 # Required-Start: $local_fs $remote_fs $network $named
     16 # Required-Stop: $local_fs $remote_fs $network
     17 # Should-Start: distcache
     18 # Short-Description: start and stop Apache HTTP Server
     19 # Description: The Apache HTTP Server is an extensible server
     20 # implementing the current HTTP standards.
     21 ### END INIT INFO
     22 # Source function library.
     23 . /etc/rc.d/init.d/functions
     24 if [ -f /etc/sysconfig/httpd ]; then
     25 . /etc/sysconfig/httpd
     26 fi
     27 # Start httpd in the C locale by default.
     28 HTTPD_LANG=${HTTPD_LANG-"C"}
     29 # This will prevent initlog from swallowing up a pass-phrase prompt if
     30 # mod_ssl needs a pass-phrase from the user.
     31 INITLOG_ARGS=""
     32 # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
     33 # with the thread-based "worker" MPM; BE WARNED that some modules may not
     34 # work correctly with a thread-based MPM; notably PHP will refuse to start.
     35 # Path to the apachectl script, server binary, and short-form for messages.
     36 #
     37 # 需要修改的地方有apachectl、httpd、pidfile(pidfile 的路径和Apache 的配置文件中Pidfile filename 的路径一样)的路径
     38 # by sigexukun
     39 # 2015 年12 月21 日
     40 apachectl=/usr/local/lamp/apache2/bin/apachectl
     41 httpd=${HTTPD-/usr/local/lamp/apache2/bin/httpd}
     42 prog=httpd
     43 pidfile=${PIDFILE-/var/run/httpd/httpd.pid}
     44 lockfile=${LOCKFILE-/var/lock/subsys/httpd}
     45 RETVAL=0
     46 STOP_TIMEOUT=${STOP_TIMEOUT-10}
     47 # The semantics of these two functions differ from the way apachectl does
     48 # things -- attempting to start while running is a failure, and shutdown
     49 # when not running is also a failure. So we just do it the way init scripts
     50 # are expected to behave here.
     51 start() {
     52 echo -n $"Starting $prog: "
     53 LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
     54 RETVAL=$?
     55 echo
     56 [ $RETVAL = 0 ] && touch ${lockfile}
     57 return $RETVAL
     58 }
     59 # When stopping httpd, a delay (of default 10 second) is required
     60 # before SIGKILLing the httpd parent; this gives enough time for the
     61 # httpd parent to SIGKILL any errant children.
     62 stop() {
     63 echo -n $"Stopping $prog: "
     64 killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
     65 RETVAL=$?
     66 echo
     67 [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
     68 }
     69 reload() {
     70 echo -n $"Reloading $prog: "
     71 if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
     72 RETVAL=6
     73 echo $"not reloading due to configuration syntax error"
     74 failure $"not reloading $httpd due to configuration syntax error"
     75 else
     76 # Force LSB behaviour from killproc
     77 LSB=1 killproc -p ${pidfile} $httpd -HUP
     78 RETVAL=$?
     79 if [ $RETVAL -eq 7 ]; then
     80 failure $"httpd shutdown"
     81 fi
     82 fi
     83 echo
     84 }
     85 # See how we were called.
     86 case "$1" in
     87 start)
     88 start
     89 ;;
     90 stop)
     91 stop
     92 ;;
     93 status)
     94 status -p ${pidfile} $httpd
     95 RETVAL=$?
     96 ;;
     97 restart)
     98 stop
     99 start
    100 ;;
    101 condrestart|try-restart)
    102 if status -p ${pidfile} $httpd >&/dev/null; then
    103 stop
    104 start
    105 fi
    106 ;;
    107 force-reload|reload)
    108 reload
    109 ;;
    110 graceful|help|configtest|fullstatus)
    111 $apachectl $@
    112 RETVAL=$?
    113 ;;
    114 *)
    115 echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
    116 RETVAL=2
    117 esac
    118 exit $RETVAL

     在centos6.7上测试通过,理论上和版本无关,欢迎测试.

    其中

    . file的写法的意思是:

    如果一个文件需要执行,必须有可执行的权限,但是有时候我们比较懒,不想修改权限,这之后就可以使用:

    . 空格 文件

    的写法,不过这种执行方式只有root用户可用

  • 相关阅读:
    mysql 历史版本下载
    mysql 5.7 版本 You must reset your password using ALTER USER statement before executing this statement报错处理
    5.7 zip 版本的安装 以及遇到的坑
    mysql 5.6zip版本的卸载与5.7 zip 版本的安装
    mysql数据库的备份与还原
    本地Navicat连接docker里的mysql
    docker修改数据库密码
    docker 在push镜像到本地registry出现的500 Internal Server Error
    linux 没有界面内容显示不全解决办法
    json与map互相转换
  • 原文地址:https://www.cnblogs.com/quinnxu/p/5070460.html
Copyright © 2011-2022 走看看