Linux 服务不支持 chkconfig
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5133552/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Service doesn't support chkconfig
提问by user565447
Good day,programmers. I have a problem. Please help. I am creating a service, which must load automatically when Linux is being loaded. So,I copied the script into the directory /etc/rc.d/init.d or /etc/init.d/. But when I am preforming the command
程序员们,大家好。我有个问题。请帮忙。我正在创建一个服务,它必须在加载 Linux 时自动加载。因此,我将脚本复制到目录 /etc/rc.d/init.d 或 /etc/init.d/ 中。但是当我执行命令时
chkconfig --add listOfProcesses
an error occurs:
出现错误:
service listOfProcesses doesn't support chkconfig
Here is the content of the script. I have found the first version in the Google and have used it as a pattern.
这是脚本的内容。我在 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 "" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $"Usage: #!/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 "" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
reload
;;
force-reload)
force_reload
;;
*)
echo $"Usage: #!/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.
{start|stop|restart|reload|force-reload}"
exit 2
esac
exit $?
# Show the list of processes
function showListOfProcesses {
top > /dev/tty2;
}
{start|stop|restart}"
exit 1
esac
exit $?
exit 0;
The second version was made from the cron script. I found the cron script,copied it, and changed it, so I used it as the pattern.
第二个版本是由 cron 脚本制作的。我找到了 cron 脚本,复制并更改了它,因此我将其用作模式。
##代码##But the situation hadn't changed. What is the problem? What is wrong in the script?
但情况并没有改变。问题是什么?脚本有什么问题?
回答by SiegeX
Look at all the scripts that chkconfig
can turn on or off in /etc/rc.d/init.d, you'll notice that the top few comments are very important. See How-To manage services with chkconfig and service
查看/etc/rc.d/init.d中所有chkconfig
可以打开或关闭的脚本,您会注意到前几条注释非常重要。请参阅如何使用 chkconfig 和 service 管理服务
You have a script called listofprocesses
but to chkconfig
this script looks like crond
due to the 3rd line and thus it does not find any script called listofprocesses
你有一个脚本被调用,listofprocesses
但由于第三行,chkconfig
这个脚本看起来像crond
,因此它没有找到任何被调用的脚本listofprocesses
You'll also most certainly want to change chkconfig: 2345 90 60
. Which says which run levels it should be on (in this case 2, 3, 4 and 5), what it's start order is (90) and what its kill order is (60).
你肯定也想改变chkconfig: 2345 90 60
。这说明它应该处于哪个运行级别(在这种情况下是 2、3、4 和 5),它的开始顺序是(90),它的终止顺序是(60)。
You can check the service is correctly set up with chkconfig --list listofprocesses
.
您可以检查服务是否正确设置chkconfig --list listofprocesses
。
回答by Techmag
Here is an excellent map of the elements that need to be in an init script, to implement what chkconfig and the init subsystem is doing, and what each element actually does:
这是需要在 init 脚本中的元素的优秀映射,以实现 chkconfig 和 init 子系统正在做什么,以及每个元素实际做什么:
回答by colin
Looks like the max priority is 99, at least on CentOS 6.5, which is what I'm playing with right now.
看起来最大优先级是 99,至少在 CentOS 6.5 上,这就是我现在正在玩的。
回答by satya
I was also facing this issue and it was not able to call stop function during shutdown. found the solution after trying so many suggestions on net. You need to add "touch /var/lock/subsys/" for start and rm -f /var/lock/subsys/" for stop functions in script. Stop may not work for first reboot as lock may be not available during shutdown but will start working from next reboot.
我也遇到了这个问题,在关机期间无法调用停止功能。在网上尝试了这么多建议后找到了解决方案。您需要在脚本中添加“touch /var/lock/subsys/”用于启动和 rm -f /var/lock/subsys/“用于停止功能。停止可能不适用于第一次重启,因为在关机期间锁可能不可用,但将从下次重新启动开始工作。
Enjoy....:)
享受....:)
Satya
萨蒂亚
回答by Adi
Just add the following line at the top:
# chkconfig: - 99 10
it should do the trick
只需在顶部添加以下行:# chkconfig: - 99 10
它应该可以解决问题