程序员,今天好。我有个问题。请帮忙。
我正在创建一个服务,该服务必须在加载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;
}

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

最佳答案

查看/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检查服务是否正确设置。

关于linux - 服务不支持chkconfig,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5133552/

10-11 20:13