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

servicehttpd start

servicehttpd status

servicehttpd stop

servicehttpd restart



本文转自 boy461205160 51CTO博客,原文链接:http://blog.51cto.com/461205160/1730513

相关文章
|
23天前
|
消息中间件 监控 数据挖掘
基于RabbitMQ与Apache Flink构建实时分析系统
【8月更文第28天】本文将介绍如何利用RabbitMQ作为数据源,结合Apache Flink进行实时数据分析。我们将构建一个简单的实时分析系统,该系统能够接收来自不同来源的数据,对数据进行实时处理,并将结果输出到另一个队列或存储系统中。
87 2
|
28天前
|
存储 消息中间件 人工智能
AI大模型独角兽 MiniMax 基于阿里云数据库 SelectDB 版内核 Apache Doris 升级日志系统,PB 数据秒级查询响应
早期 MiniMax 基于 Grafana Loki 构建了日志系统,在资源消耗、写入性能及系统稳定性上都面临巨大的挑战。为此 MiniMax 开始寻找全新的日志系统方案,并基于阿里云数据库 SelectDB 版内核 Apache Doris 升级了日志系统,新系统已接入 MiniMax 内部所有业务线日志数据,数据规模为 PB 级, 整体可用性达到 99.9% 以上,10 亿级日志数据的检索速度可实现秒级响应。
AI大模型独角兽 MiniMax 基于阿里云数据库 SelectDB 版内核 Apache Doris 升级日志系统,PB 数据秒级查询响应
|
29天前
|
关系型数据库 MySQL 应用服务中间件
win7系统搭建PHP+Mysql+Apache环境+部署ecshop项目
这篇文章介绍了如何在Windows 7系统上搭建PHP、MySQL和Apache环境,并部署ECShop项目,包括安装配置步骤、解决常见问题以及使用XAMPP集成环境的替代方案。
37 1
win7系统搭建PHP+Mysql+Apache环境+部署ecshop项目
|
28天前
|
Ubuntu Linux 测试技术
在Linux中,已知 apache 服务的访问日志按天记录在服务器本地目录/app/logs 下,由于磁盘空间紧张现在要求只能保留最近7天的访问日志,请问如何解决?
在Linux中,已知 apache 服务的访问日志按天记录在服务器本地目录/app/logs 下,由于磁盘空间紧张现在要求只能保留最近7天的访问日志,请问如何解决?
|
30天前
|
Ubuntu 应用服务中间件 Linux
在Linux中,如何查看Apache或Nginx服务的状态?
在Linux中,如何查看Apache或Nginx服务的状态?
|
1月前
|
关系型数据库 Linux 网络安全
"Linux系统实战:从零开始部署Apache+PHP Web项目,轻松搭建您的在线应用"
【8月更文挑战第9天】Linux作为服务器操作系统,凭借其稳定性和安全性成为部署Web项目的优选平台。本文以Apache Web服务器和PHP项目为例,介绍部署流程。首先,通过包管理器安装Apache与PHP;接着创建项目目录,并上传项目文件至该目录;根据需要配置Apache虚拟主机;最后重启Apache服务并测试项目。确保防火墙允许HTTP流量,正确配置数据库连接,并定期更新系统以维持安全。随着项目复杂度提升,进一步学习高级配置将变得必要。
79 0
|
2月前
|
Linux 持续交付 Apache
在Linux中通过ansible自动化部署apache服务
【7月更文挑战第11天】Linux中用Ansible自动化部署Apache服务:1. 确保Ansible已安装;2. 在`/etc/ansible/hosts`配置目标主机,如\[webservers\] server1 server2;3. 编写Playbook `apache_deploy.yml`更新系统并安装、启动Apache;4. 执行`ansible-playbook apache_deploy.yml`。适用于快速部署至多台服务器,减少配置错误和成本。
|
3月前
|
消息中间件 存储 Java
深度探索:使用Apache Kafka构建高效Java消息队列处理系统
【6月更文挑战第30天】Apache Kafka是分布式消息系统,用于高吞吐量的发布订阅。在Java中,开发者使用Kafka的客户端库创建生产者和消费者。生产者发送序列化消息到主题,消费者通过订阅和跟踪偏移量消费消息。Kafka以持久化、容灾和顺序写入优化I/O。Java示例代码展示了如何创建并发送/接收消息。通过分区、消费者组和压缩等策略,Kafka在高并发场景下可被优化。
104 1
|
3月前
|
应用服务中间件 Apache nginx
apache、nginx开启rewrite重写服务及伪静态
apache、nginx开启rewrite重写服务及伪静态
114 4
|
2月前
|
消息中间件 存储 Java
Apache Kafka是分布式消息系统,用于高吞吐量的发布订阅
【7月更文挑战第1天】Apache Kafka是分布式消息系统,用于高吞吐量的发布订阅。在Java中,开发者使用Kafka的客户端库创建生产者和消费者。生产者发送消息到主题,消费者订阅并消费。Kafka提供消息持久化、容灾机制,支持分区和复制以确保高可用性。通过优化如分区、批处理和消费者策略,可适应高并发场景。简单的Java示例展示了如何创建和交互消息。
42 0

推荐镜像

更多