Apache源码包添加启动脚本到系统服务

简介:

手动编译apache源码包安装的话,apache是没有启动脚本的,也就是说用户不能通过简单的通过/etc/init.d/httpd(start|stop|restart)来启动/关闭/重新启动。

其实源码里已经有启动的脚本,我们要修改下即可,把Apache加入系统SysV服务中来。

在源码httpd-2.x.x/build/rpm中存在httpd.init    #httpd.ini就是apache启动脚本

拷贝命令如下:

cp httpd.init /etc/init.d/httpd

编辑该httpd文件:

#!/bin/bash

#

# Licensed to the ApacheSoftware Foundation (ASF) under one or more

# contributor licenseagreements.  See the NOTICE filedistributed with

# this work for additionalinformation regarding copyright ownership.

# The ASF licenses this fileto You under the Apache License, Version 2.0

# (the "License");you may not use this file except in compliance with

# the License.  You may obtain a copy of the License at

#

#     http://www.apache.org/licenses/LICENSE-2.0

#

# Unless required byapplicable law or agreed to in writing, software

# distributed under theLicense is distributed on an "AS IS" BASIS,

# WITHOUT WARRANTIES ORCONDITIONS OF ANY KIND, either express or implied.

# See the License for thespecific language governing permissions and

# limitations under theLicense.

#

#

# httpd        Startup script for the Apache WebServer

#

# chkconfig: - 85 15     #可以改成chkconfig: 35 85 15

# description: The ApacheHTTP Server is an efficient and extensible \

#             server implementing the currentHTTP standards.

# processname: httpd

# pidfile: /var/run/httpd.pid

# config:/etc/sysconfig/httpd

#

### BEGIN INIT INFO

# Provides: httpd

# Required-Start: $local_fs$remote_fs $network $named

# Required-Stop: $local_fs$remote_fs $network

# Should-Start: distcache

# Short-Description: start andstop Apache HTTP Server

# Description: The ApacheHTTP Server is an extensible server

#  implementing the current HTTP standards.

### END INIT INFO

# Source function library.

. /etc/rc.d/init.d/functions

# What were we called?Multiple instances of the same daemon can be

# created by creatingsuitably named symlinks to this startup script

prog=$(basename $0 | sed -e's/^[SK][0-9][0-9]//')

if [ -f/etc/sysconfig/${prog} ]; then

        . /etc/sysconfig/${prog}

fi

# Start httpd in the C localeby default.

HTTPD_LANG=${HTTPD_LANG-"C"}

# This will prevent initlogfrom swallowing up a pass-phrase prompt if

# mod_ssl needs a pass-phrasefrom the user.

INITLOG_ARGS=""

# SetHTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server

# with the thread-based"worker" MPM; BE WARNED that some modules may not

# work correctly with athread-based MPM; notably PHP will refuse to start.

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

pidfile=${PIDFILE-/usr/local/apache/logs/${prog}.pid}

lockfile=${LOCKFILE-/var/lock/subsys/${prog}}

RETVAL=0

 

 

# check for 1.3 configuration

check13 () {

       CONFFILE=/usr/local/apache/conf/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 configurationdirectives found"

              echo 1>&2 " please read@docdir@/migration.html"

              failure "Apache 1.3 config directives test"

              echo

              exit 1

       fi

}

 

# The semantics of these twofunctions differ from the way apachectl does

# things -- attempting tostart while running is a failure, and shutdown

# when not running is also afailure.  So we just do it the way initscripts

# are expected to behavehere.

start() {

        echo -n $"Starting $prog: "

        check13 || exit 1

        LANG=$HTTPD_LANG daemon--pidfile=${pidfile} $httpd $OPTIONS

        RETVAL=$?

        echo

        [ $RETVAL = 0 ] && touch${lockfile}

        return $RETVAL

}

stop() {

       echo -n $"Stopping $prog: "

       killproc -p ${pidfile} -d 10 $httpd

       RETVAL=$?

       echo

       [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}

}

reload() {

       echo -n $"Reloading $prog: "

       check13 || exit 1

       killproc -p ${pidfile} $httpd -HUP

       RETVAL=$?

       echo

}

 

# See how we were called.

case "$1" in

  start)

       start

       ;;

  stop)

       stop

       ;;

  status)

        if ! test -f ${pidfile}; then

            echo $prog is stopped

            RETVAL=3

        else 

            status -p ${pidfile} $httpd

            RETVAL=$?

        fi

        ;;

  restart)

       stop

       start

       ;;

  condrestart)

       if test -f ${pidfile} && status -p ${pidfile} $httpd>&/dev/null; then

              stop

              start

       fi

       ;;

  reload)

        reload

       ;;

  configtest)

        LANG=$HTTPD_LANG $httpd $OPTIONS -t

        RETVAL=$?

        ;;

  graceful)

        echo -n $"Gracefully restarting$prog: "

        LANG=$HTTPD_LANG $httpd $OPTIONS -k $@

        RETVAL=$?

        echo

        ;;

  *)

       echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|graceful|help|configtest}"

       exit 1

esac

exit $RETVAL

注意文件中有三处主要的地方需要修改下的:

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

pidfile=${PIDFILE-/usr/local/apache2/logs/${prog}.pid}

CONFFILE=/usr/local/apache2/conf/httpd.conf

上面是我自己的路径请根据实际情况更改相应的路径!

然后运行如下命令:

ls–l httpd   #查看httpd是否有执行权限

chkmod+x httpd  #添加执行权限

chkconfig--add httpd   #添加httpd到系统服务

chkconfig--level 35 httpd on  #设置httpd运行级别为35,开机自动运行

这样一来,启动、停止、重启Apache就可以用以下方式了:

/etc/init.d/httpd start

/etc/init.d/httpd stop

/etc/init.d/httpd restart

service httpd start

service httpd status

service httpd stop

service httpd restart




本文转自 Mr_sheng 51CTO博客,原文链接:http://blog.51cto.com/sf1314/1980623
相关文章
|
1月前
|
运维 Linux Apache
Linux Apache服务详解——Apache虚拟目录与禁止显示目录列表实战
Linux Apache服务详解——Apache虚拟目录与禁止显示目录列表实战
22 2
|
1月前
|
域名解析 Linux Apache
Linux Apache服务详解——虚拟网站主机功能实战
Linux Apache服务详解——虚拟网站主机功能实战
34 5
|
1月前
|
Linux 应用服务中间件 Apache
Linux Apache服务详解——Apache服务基础知识
Linux Apache服务详解——Apache服务基础知识
34 2
|
4月前
|
安全 网络协议 Linux
Linux加强篇010-使用Apache服务部署静态网站
山重水复疑无路,柳暗花明又一村
282 0
|
2月前
|
前端开发 Java 数据库连接
Springboot-MyBatis配置-配置端口号与服务路径(idea社区版2023.1.4+apache-maven-3.9.3-bin)
Springboot-MyBatis配置-配置端口号与服务路径(idea社区版2023.1.4+apache-maven-3.9.3-bin)
33 0
|
6月前
|
Linux 网络安全 Apache
百度搜索:蓝易云 ,linux系统 Apache服务配置教程。
现在,您可以通过浏览器访问您的网站。在浏览器中输入服务器的IP地址或域名,即可访问默认网站或配置的虚拟主机。以上是在Linux系统上配置Apache服务的教程。请根据您的需求进行必要的配置和修改。
83 0
|
1月前
|
Web App开发 存储 Linux
Linux Apache服务详解——Apache服务访问控制
Linux Apache服务详解——Apache服务访问控制
328 7
|
1月前
|
存储 SQL 消息中间件
Apache Hudi:统一批和近实时分析的存储和服务
Apache Hudi:统一批和近实时分析的存储和服务
32 0
|
1月前
|
存储 Apache
一文彻底理解Apache Hudi的清理服务
一文彻底理解Apache Hudi的清理服务
33 0
|
1月前
|
运维 Linux 网络安全
Linux Apache服务详解——用户个人主页实战
Linux Apache服务详解——用户个人主页实战
22 1

热门文章

最新文章

推荐镜像

更多