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. .......