Systemd Service Type

  

 

forking类型

使用Type=forking时,要求ExecStart启动的命令自身就是以daemon模式运行的。
而以daemon模式运行的进程都有一个特性:总是会有一个瞬间退出的中间父进程,
例如,nginx命令默认以daemon模式运行,所以可直接将其配置为forking类型:

 

simple类型

Type=simple是一种最常见的通过systemd服务系统运行用户自定义命令的类型,也是省略Type指令时的默认类型。
Type=simple类型的服务只适合那些在shell下运行在前台的命令。也就是说,当一个命令本身会以daemon模式运行时,将不能使用simple,而应该使用Type=forking。比如ls命令、sleep命令、非daemon模式运行的nginx进程以及那些以前台调试模式运行的进程,在理论上都可以定义为simple类型的服务。

 


If set to forking, it is expected that the process configured with ExecStart= will call fork() as part of its start-up. The parent process is expected to exit when
start-up is complete and all communication channels are set up. The child continues to run as the main service process, and the service manager will consider the
unit started when the parent process exits. .......
posted @ 2021-11-02 15:40  ascertain  阅读(1057)  评论(0编辑  收藏  举报