linux脚本中什么是start-stop-daemon ?

时间:2022-07-26 15:41:50

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 /”位置。

2 个解决方案

#1


55  

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[其他参数]什么

start something, if something wasn't already running. If it was running, do nothing.

开始一些事情,如果有些事情还没有开始。如果它在运行,什么也不要做。

start-stop-daemon -K [other arguments] something

start-stop-daemon -K(其他参数

stop something. If something wasn't running, do nothing.

停止的东西。如果有什么东西没在运行,什么也不要做。

The man page provides 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
  • -m =制作PID文件。当您的进程不创建自己的PID文件时,可以使用它,并与—background一起使用
  • --oknodo = return 0, not 1 if no actions are taken by the daemon
  • ——oknodo =返回0,如果守护进程没有执行任何操作,则返回1
  • --pidfile ${PIDFILE} = check whether the PID file has been created or not
  • ——pidfile ${pidfile} =检查PID文件是否已创建
  • --exec = make sure the processes are instances of this executable (in your case, DAEMON)
  • ——exec =确保流程是此可执行文件的实例(在您的示例中是守护进程)

#2


9  

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/骨架文件(例如/etc/ initc)。d/rajeevdaemon或另一个好名字),这是一个shell脚本,有很多注释,编辑它以满足您的需要。然后添加适当的符号链接,例如/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

#1


55  

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[其他参数]什么

start something, if something wasn't already running. If it was running, do nothing.

开始一些事情,如果有些事情还没有开始。如果它在运行,什么也不要做。

start-stop-daemon -K [other arguments] something

start-stop-daemon -K(其他参数

stop something. If something wasn't running, do nothing.

停止的东西。如果有什么东西没在运行,什么也不要做。

The man page provides 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
  • -m =制作PID文件。当您的进程不创建自己的PID文件时,可以使用它,并与—background一起使用
  • --oknodo = return 0, not 1 if no actions are taken by the daemon
  • ——oknodo =返回0,如果守护进程没有执行任何操作,则返回1
  • --pidfile ${PIDFILE} = check whether the PID file has been created or not
  • ——pidfile ${pidfile} =检查PID文件是否已创建
  • --exec = make sure the processes are instances of this executable (in your case, DAEMON)
  • ——exec =确保流程是此可执行文件的实例(在您的示例中是守护进程)

#2


9  

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/骨架文件(例如/etc/ initc)。d/rajeevdaemon或另一个好名字),这是一个shell脚本,有很多注释,编辑它以满足您的需要。然后添加适当的符号链接,例如/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