gpt4 book ai didi

linux - 服务不支持 chkconfig

转载 作者:IT老高 更新时间:2023-10-28 12:40:47 26 4
gpt4 key购买 nike

程序员们,你们好。我有个问题。请帮忙。我正在创建一个服务,它必须在加载 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com