开发者社区> 科技小能手> 正文

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

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
Elasticsearch实战(三)-MacOS下载安装启动Elasticserch、Kibana
Elasticsearch实战(三)-MacOS下载安装启动Elasticserch、Kibana
42 0
Fundebug微信小程序BUG监控服务支持Source Map
摘要: 自动还原真实出错位置,快速修复BUG。 Source Map功能 微信小程序的Source Map功能目前只在 iOS 6.7.2 及以上版本支持。 微信小程序在打包时,会将所有 js 代码打包成一个文件,从而减少体积,加快访问速度。
1291 0
Qt [GC9-5]:给我的程序添加启动画面(触发编译警告)
Qt [GC9-5]:给我的程序添加启动画面(触发编译警告)
34 0
为什么SAP GUI里的传统事务码能通过Fiori Launchpad启动
为什么SAP GUI里的传统事务码能通过Fiori Launchpad启动
29 0
mysql:failed,启动失败,mmap failed-Cannot allocate memory for the buffer pool
在使用mysql5.7进行当做网站的数据库时,有时候会莫名死掉,网站也会因此打不开,重新启动mysql也无法正常启动。通过查看mysql的告警日志发现: cat /etc/my.cnf ... log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid ... cat /var/log/mysqld.log 发现是因为mysql无法分配足够的内存供使用,因此无法正常启动。
1124 0
C++程序中嵌入Ruby脚本系统
Ruby,一种为简单快捷面向对象编程(面向对象程序设计)而创的脚本语言,由日本人松本行弘(まつもとゆきひろ,英译:Yukihiro Matsumoto,外号matz)开发,遵守GPL协议和Ruby License。
1325 0
23705
文章
0
问答
文章排行榜
最热
最新
相关电子书
更多
OceanBase 入门到实战教程
立即下载
阿里云图数据库GDB,加速开启“图智”未来.ppt
立即下载
实时数仓Hologres技术实战一本通2.0版(下)
立即下载