Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  shell  >  正文 shell脚本管理httpd进程实例

shell脚本管理httpd进程实例

发布时间:2014-12-21   编辑:www.jquerycn.cn
本文介绍了一个管理httpd进程的shell脚本,用脚本管理httpd进程非常方便,有需要的朋友参考学习下。

使用shell脚本管理httpd执行文件。
代码:
 

复制代码 代码示例:
#!/bin/bash 

# httpd        Startup script for the Apache HTTP Server 

# chkconfig: - 85 15 
# description: Apache is a World Wide Web server.  It is used to serve \ 
#          HTML files and CGI. 
# processname: httpd 
# config: /www/wdlinux/apache/conf/httpd.conf 
# config: /etc/sysconfig/httpd 
# pidfile: /www/wdlinux/apache/logs/httpd.pid 
 
# Source function library. 
. /etc/rc.d/init.d/functions 
 
if [ -f /etc/sysconfig/httpd ]; then 
        . /etc/sysconfig/httpd 
fi 
 
# Start httpd in the C locale by default. 
HTTPD_LANG=${HTTPD_LANG-"C"} 
 
# This will prevent initlog from swallowing up a pass-phrase prompt if 
# mod_ssl needs a pass-phrase from the user. 
INITLOG_ARGS="" 
 
# Set HTTPD=/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 a thread-based MPM; notably PHP will refuse to start. 
 
# Path to the apachectl script, server binary, and short-form for messages. 
apachectl=/www/wdlinux/apache/bin/apachectl 
httpd=${HTTPD-/www/wdlinux/apache/bin/httpd} 
prog=httpd 
pidfile=${PIDFILE-/www/wdlinux/apache/logs/httpd.pid} 
lockfile=${LOCKFILE-/var/lock/subsys/httpd} 
RETVAL=0 
 
# The semantics of these two functions differ from the way apachectl does 
# things -- attempting to start while running is a failure, and shutdown 
# when not running is also a failure.  So we just do it the way init scripts 
# are expected to behave here. 
start() { 
        echo -n $"Starting $prog: " 
        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS 
        RETVAL=$? 
        echo 
        [ $RETVAL = 0 ] && touch ${lockfile} 
        return $RETVAL 

 
# When stopping httpd a delay of >10 second is required before SIGKILLing the 
# httpd parent; this gives enough time for the httpd parent to SIGKILL any 
# errant children. 
stop() { 
    echo -n $"Stopping $prog: " 
    killproc -p ${pidfile} -d 3 $httpd 
    RETVAL=$? 
    echo 
    [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} 

reload() { 
    echo -n $"Reloading $prog: " 
    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then 
        RETVAL=$? 
        echo $"not reloading due to configuration syntax error" 
        failure $"not reloading $httpd due to configuration syntax error" 
    else 
        killproc -p ${pidfile} $httpd -HUP 
        RETVAL=$? 
    fi 
    echo 

 
# See how we were called. 
case "$1" in 
  start) 
    start 
    ;; 
  stop) 
    stop 
    ;; 
  status) 
        status -p ${pidfile} $httpd 
    RETVAL=$? 
    ;; 
  restart) 
    stop 
    start 
    ;; 
  condrestart) 
    if [ -f ${pidfile} ] ; 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 

代码说明: 
注意目录权限,写好后给此文件一个可执行权限:
 

复制代码 代码示例:
chmod 755 /etc/rc.d/init.d/httpd
service httpd start stop restart..........

添加到开机启动:
 

复制代码 代码示例:
chkconfig --add httpd
chkconfig --level 3 httpd on

您可能感兴趣的文章:
shell脚本管理httpd进程实例
shell条件测试语句实例-测试apache是否开启
shell脚本实例与shell参数用法
inux shell初级入门教程
php中mysql_connect与mysql_pconncet的用法区别
生产环境中用到的二个shell脚本
apache(with perl)的启动脚本一例
Docker 安装 Apache
python shell是什么
sed清除注释的脚本一例

关键词: httpd  linux shell  shell  进程   
[关闭]