httpd启动脚本

#!/bin/bash
# chkconfig: - 85 15
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
        . /etc/sysconfig/httpd
fi
INITLOG_ARGS=""
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
RETVAL=0
check13 () {
CONFFILE=/etc/httpd/httpd.conf
GONE="(ServerType|BindAddress|Port|AddModule|ClearModuleList|"
GONE="${GONE}AgentLog|RefererLog|RefererIgnore|FancyIndexing|"
GONE="${GONE}AccessConfig|ResourceConfig)"
if grep -Eiq "^[[:space:]]*($GONE)" $CONFFILE; then
  echo
  echo 1>&2 " Apache 1.3 configuration directives found"
  echo 1>&2 " please read @docdir@/migration.html"
  failure "Apache 1.3 config directives test"
  echo
  exit 1
fi
}
start() {
        echo -n $"Starting $prog: "
        check13 || exit 1
        daemon $httpd $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch /var/lock/subsys/httpd
        return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/httpd /var/run/httpd.pid
}
reload() {
echo -n $"Reloading $prog: "
check13 || exit 1
killproc $httpd -HUP
RETVAL=$?
echo
}
case "$1" in
  start)
start
;;
  stop)
stop
;;
  status)
        status $httpd
RETVAL=$?
;;
  restart)
stop
start
;;
  condrestart)
if [ -f /var/run/httpd.pid ] ; then
  stop
  start
fi
;;
  reload)
        reload
;;
  graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
  *)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
exit 1
esac
exit $RETVAL

将改脚本放到/etc/rc.d/init.d/httpd中

将脚本中的如下内容修改成自己的apache的安装的路径:

apachectl=/usr/local/apache/bin/apachectl

httpd=${HTTPD-/usr/local/apache/bin/httpd}

CONFFILE=/etc/httpd/httpd.conf
设置开机自启动
# chown 755 /etc/init.d/httpd
# chkconfig --add httpd
# chkconfig httpd on



posted @ 2016-07-05 16:04  fansik  阅读(311)  评论(0编辑  收藏