服务不支持chkconfig

时间:2011-02-27 13:50:08

标签: linux bash

美好的一天,程序员。我有个问题。请帮忙。 我正在创建一个服务,它必须在加载Linux时自动加载。因此,我将脚本复制到目录/etc/rc.d/init.d或/etc/init.d/中。但是当我正在执行命令时

chkconfig --add listOfProcesses

发生错误:

service  listOfProcesses doesn't support chkconfig

以下是脚本的内容。我在Google中找到了第一个版本,并将其用作模式。

#!/bin/bash
# listOfProcesses   Start the process which will show the list of processes
# chkconfig: 345 110 02
# description: This process shows current time and the list of processes
# processname: listOfProcesses
### BEGIN INIT INFO
# Provides:
# Required-Start:
# Required-Stop:
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: shows current time and the list of processes
# Description: This process shows current time and the list of processes
### END INIT INFO
# Source function library.
KIND="listOfProcesses"
    start() {
            echo -n $"Starting $KIND services: "
            daemon /home/myscript
            echo
    }   

    stop() {
            echo -n $"Shutting down $KIND services: "
            killproc /home/myscript
            echo
    }   

    restart() {
                echo -n $"Restarting $KIND services: "   
                   killproc /home/myscript
               daemon /home/myscript
               echo
    }   

    case "$1" in
      start)
              start
            ;;
      stop)
              stop
            ;;
      restart)
              restart
            ;;
      *)
            echo $"Usage: $0 {start|stop|restart}"
            exit 1
    esac
    exit $?

exit 0;

第二个版本是由cron脚本制作的。我找到了cron脚本,复制了它并更改了它,所以我用它作为模式。

#!/bin/sh
#
# crond          Start/Stop the cron clock daemon.
#
# chkconfig: 2345 90 60
# description: cron is a standard UNIX program that runs user-specified \
#              programs at periodic scheduled times. vixie cron adds a \
#              number of features to the basic UNIX cron, including better \
#              security and more powerful configuration options.

### BEGIN INIT INFO
# Provides: crond crontab
# Required-Start: $local_fs $syslog
# Required-Stop: $local_fs $syslog
# Default-Start:  2345
# Default-Stop: 90
# Short-Description: run cron daemon
# Description: cron is a standard UNIX program that runs user-specified 
#              programs at periodic scheduled times. vixie cron adds a 
#              number of features to the basic UNIX cron, including better 
#              security and more powerful configuration options.
### END INIT INFO

rights=whoami;
root=root;
[ -f "$rights"=="$root" ] || { 
echo "this programme requires root rights";
exit 1;
}

# Source function library.
. /etc/rc.d/init.d/functions

start() {
  echo -n $"Starting $KIND services: ";
  daemon showListOfProcesses;
}

stop() {
 echo -n $"Shutting down $KIND services: ";
 killproc showListOfProcesses;
}

restart() {
stop
start
}

reload() {
    restart;
}

force_reload() {
    # new configuration takes effect after restart
    restart
}

case "$1" in
start)
    start
    ;;
stop)
    stop
    ;;
restart)
     restart
    ;;
reload)
    reload
    ;;
force-reload)
    force_reload
    ;;
*)
    echo $"Usage: $0 {start|stop|restart|reload|force-reload}"
    exit 2
esac
exit $?

# Show the list of processes
function showListOfProcesses {
  top > /dev/tty2;
}

但情况并没有改变。问题是什么?脚本有什么问题?

5 个答案:

答案 0 :(得分:52)

查看{em> /etc/rc.d/init.d 中chkconfig可以打开或关闭的所有脚本,您会注意到前几条评论非常重要。见How-To manage services with chkconfig and service

#!/bin/sh
#
# crond          Start/Stop the cron clock daemon.
#
# chkconfig: 2345 90 60
# description: cron is a standard UNIX program that runs user-specified \
#              programs at periodic scheduled times. vixie cron adds a \
#              number of features to the basic UNIX cron, including better \
#              security and more powerful configuration options.

你有一个名为listofprocesses的脚本,但是chkconfig这个脚本由于第3行而看起来像crond,因此它找不到任何名为listofprocesses的脚本

您也肯定想要更改chkconfig: 2345 90 60。其中说明它应该处于哪个运行级别(在这种情况下为2,3,4和5),它的起始顺序是(90)以及它的终止顺序是什么(60)。

您可以使用chkconfig --list listofprocesses检查服务是否正确设置。

答案 1 :(得分:17)

只需在顶部添加以下行:  #chkconfig: - 99 10
它应该做的伎俩

答案 2 :(得分:4)

这是一个优秀的元素映射,需要在init脚本中实现,以实现chkconfig和init子系统正在执行的操作,以及每个元素实际执行的操作:

http://www.tldp.org/HOWTO/HighQuality-Apps-HOWTO/boot.html

答案 3 :(得分:3)

看起来最高优先级是99,至少在CentOS 6.5上,这就是我现在正在玩的。

答案 4 :(得分:-1)

我也遇到了这个问题,并且在关机期间无法调用停止功能。在网上尝试了这么多建议后找到了解决方案。 你需要添加" touch / var / lock / subsys /" for start和rm -f / var / lock / subsys /"用于脚本中的停止功能。停止可能无法在第一次重新启动时起作用,因为在关机期间锁定可能不可用,但会在下次重启时开始工作。

享受....:)

萨蒂亚