service脚本无法加入chkconfig时的解决方法

发布时间:2020-02-16编辑:脚本学堂
/etc/init.d目录下的apache服务脚本httpd在执行chkconfig --add httpd时出现错误:
“service httpd does not support chkconfig”

/etc/init.d目录下的apache服务脚本httpd在执行chkconfig --add httpd时出现错误:
“service httpd does not support chkconfig”

分析:每个服务脚本的开头的几行里都会有给chkconfig 命令用的注释。表明一些chkconfig用的信息,具体格式可以man chkconfig一下。

比如我后来在httpd文件的开头加入了一下几行,就可以了:
 

复制代码 代码如下:

#!/bin/sh
#
# Startup script for the Apache Web Server
#
# chkconfig: 345 85 15 (这个比较有意思,345代表在设置在那个level中是on的,如果一个都不想on,那就写一个横线"-",比如:chkconfig: - 85 15。后面两个数字当然代表S和K的默认排序号啦)
# description: Apache is a World Wide Web server.  It is used to serve
#              HTML files and CGI.
# processname: httpd
# pidfile: /var/run/httpd.pid
# config: /usr/local/apache2/conf/httpd.conf (我装东西比较喜欢都放在/usr/local下)
 
# Source function library.
. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/httpd ]; then
       . /etc/sysconfig/httpd
fi

INITLOG_ARGS=""

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

prog="httpd"

start()
{
    ps -ef | grep "$prog" | grep -v "grep" | grep -v "start" > /dev/null
    if [ "$?" -eq "1" ]; then
        echo -n $"Starting $prog: "
        daemon $httpd $OPTIONS
        ret=$?
        echo
        [ "$ret" -eq "0" ] && touch /var/lock/subsys/httpd
        return 0
    else
        echo "httpd running"
        return 0
    fi
}

stop()
{
    status httpd >/dev/null >&1
    ret_status=$?
    if [ $ret_status -eq 2 ]; then
        rm -f /var/lock/subsys/httpd /var/run/httpd.pid
        echo "httpd stopped"
        return 0
    elif [ $ret_status -eq 3 ]; then
        echo "httpd stopped"
        return 0
    fi
    echo -n $"Stopping $prog: "
    killproc $httpd
    ret=$?
    echo
    [ "$ret" -eq "0" ] && rm -f /var/lock/subsys/httpd /var/run/httpd.pid
    return 0
}

case "$1" in
    start)
       start
       ;;
    stop)
       stop
       ;;
    status)
       status httpd
       ;;
    restart)
       stop
       sleep 2
       start
       ;;
    *)
       echo $"Usage: $prog {start|stop|restart|status}"
       exit 1
esac