服务不支持chkconfig

use*_*447 33 linux bash

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

chkconfig --add listOfProcesses
Run Code Online (Sandbox Code Playgroud)

发生错误:

service  listOfProcesses doesn't support chkconfig
Run Code Online (Sandbox Code Playgroud)

这是脚本的内容.我在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;
Run Code Online (Sandbox Code Playgroud)

第二个版本是由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;
}
Run Code Online (Sandbox Code Playgroud)

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

Sie*_*geX 53

查看chkconfig可以在/etc/rc.d/init.d中打开或关闭的所有脚本,您会注意到前几条注释非常重要.请参见如何使用chkconfig和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.
Run Code Online (Sandbox Code Playgroud)

你有一个调用的脚本,listofprocesses但是chkconfig这个脚本看起来像是crond由于第3行而没有找到任何调用的脚本listofprocesses

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

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

  • 这个答案实际上没有指出所有的根本原因.是的,crond系列可能部分归咎于,但是`chkconfig:<run lvl> <start priority> <kill priority>`行的值不正确.**起始优先级应为0-99**. (6认同)

Adi*_*Adi 21

只需在顶部添加以下行:#chkconfig: - 99 10
它应该可以解决问题

  • 在哪里? (4认同)