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上測試經過,理論上和版本無關,歡迎測試.apache
其中centos
. file的寫法的意思是:bash
若是一個文件須要執行,必須有可執行的權限,可是有時候咱們比較懶,不想修改權限,這以後就能夠使用:ide
. 空格 文件測試
的寫法,不過這種執行方式只有root用戶可用ui