创建在操作系统启动时启动的程序/守护进程

创建在操作系统启动时启动的程序/守护进程

如何为 *nix 机器创建一个在操作系统启动时启动的守护进程?在 MacOS 上,我猜最好的选择是酿造服务。 Linux 的最佳选择是什么?

答案1

这取决于发行版,但现在许多发行版正在转向systemdinit 服务。对于这种情况,您需要创建一个 systemd 服务:请参阅 systemd.directives(7) 联机帮助页,系统主页并谷歌搜索“systemd 服务示例”。这是一个将 emacs 作为守护进程启动的示例(请参见本节中的示例 9.18)

[Unit]
Description=Emacs: the extensible, self-documenting text editor

[Service]
Type=forking
ExecStart=/usr/bin/emacs --daemon
ExecStop=/usr/bin/emacsclient --eval "(kill-emacs)"
Environment=SSH_AUTH_SOCK=%t/keyring/ssh
Restart=always

[Install]
WantedBy=default.target

相关内容