linux 脚本中的 start-stop-daemon 是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16139940/
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
What is start-stop-daemon in linux scripting?
提问by Rajeev Das
What is start-stop-daemon and how should it be used?
什么是 start-stop-daemon,应该如何使用?
I am trying to automate a particular program to run. Whenever the system starts, the program should run. For that I am writing script in /etc/init.d/
location.
我正在尝试自动运行特定程序。每当系统启动时,程序就应该运行。为此,我正在/etc/init.d/
现场编写脚本。
采纳答案by Burhan Khalid
It is a program to manage the start and stop of system level background processes (daemons). You use it by passing in parameters (such as the pid file to create/check) and command arguments for the process you want to launch.
它是一个管理系统级后台进程(守护进程)启动和停止的程序。您可以通过传入参数(例如要创建/检查的 pid 文件)和要启动的进程的命令参数来使用它。
Then, you do one of two things:
然后,您执行以下两项操作之一:
start-stop-daemon -S [other arguments] something
start-stop-daemon -S [other arguments] something
start something
, if something
wasn't already running. If it was running, do nothing.
start something
,如果something
还没有运行。如果它正在运行,则什么都不做。
start-stop-daemon -K [other arguments] something
start-stop-daemon -K [other arguments] something
stop something
. If something
wasn't running, do nothing.
停止something
。如果something
没有运行,什么都不做。
The man pageprovides more information on the various arguments. Typically a template is provided in /etc/init.d/
which has other commands for the init process that controls the running of background processes.
该手册页提供了有关的各种参数的更多信息。通常会提供一个模板,/etc/init.d/
其中包含用于控制后台进程运行的 init 进程的其他命令。
What does it mean?
这是什么意思?
start-stop-daemon --start --background -m --oknodo --pidfile ${PIDFILE} --exec ${DAEMON} -- ${TARGETDIR}
start-stop-daemon --start --background -m --oknodo --pidfile ${PIDFILE} --exec ${DAEMON} -- ${TARGETDIR}
--background
= launch as a background process-m
= make a PID file. This is used when your process doesn't create its own PID file, and is used with--background
--oknodo
= return0
, not1
if no actions are taken by the daemon--pidfile ${PIDFILE}
= check whether the PID file has been created or not--exec
= make sure the processes are instances of this executable (in your case,DAEMON
)
--background
= 作为后台进程启动-m
= 制作一个 PID 文件。这在您的进程不创建自己的 PID 文件时使用,并与--background
--oknodo
= return0
,1
如果守护进程没有采取任何行动,则不会--pidfile ${PIDFILE}
= 检查 PID 文件是否已创建--exec
= 确保进程是此可执行文件的实例(在您的情况下,DAEMON
)
回答by Basile Starynkevitch
Copy the /etc/init.d/skeleton
file(to e.g. /etc/init.d/rajeevdaemon
or another good name), which is a shell script with a lot of comments, and edit it to suit your needs. Then add appropriate symlinks from e.g. /etc/rc2.d/S98rajeevdaemon
and /etc/rc2.d/K98rajeevdaemon
to it.
复制/etc/init.d/skeleton
文件(例如/etc/init.d/rajeevdaemon
或其他好名字),这是一个带有大量注释的 shell 脚本,然后编辑它以满足您的需要。然后从 eg/etc/rc2.d/S98rajeevdaemon
和/etc/rc2.d/K98rajeevdaemon
到它添加适当的符号链接。
Read more about runlevels.
阅读有关运行级别的更多信息。
And recent (or future) Linux distributions are using more and more systemd
最近(或未来)Linux 发行版正在使用越来越多的systemd