当我从 SSH 注销时,apache2 停止

当我从 SSH 注销时,apache2 停止

我正在运行 Debian 8 Jessie,并且我的登录用户 ID 下正在运行 Apache 2.4.25-3+deb9u3。当我通过 SSH 登录到服务器然后注销时,apache 终止。Debian 9 Stretch 上也会发生这种情况。当我在 Debian 7 Wheezy(我认为是 apache 2.2)上运行时,它不是这样工作的。我可以随时登录和注销,Apache 仍会运行。

我查看了 logind.conf 并且 KillUserProcesses 设置为否。

我希望 apache2 永远不会停止运行,除非我手动停止它。有什么想法吗?

答案1

理想情况下,Apache 应该以自己的用户身份运行,例如 www-data。您以自己的身份运行它有什么原因吗?

无论如何,如果你确实需要从你自己的用户运行它,你应该nohup在命令的末尾使用 来启动它。这样,当你注销时,系统不会在你注销时向该进程发送 hup(挂断)信号。

从手册页中:

nohup(1) - Linux man page

Name

nohup - run a command immune to hangups, with output to a non-tty
Synopsis

nohup COMMAND [ARG]...
nohup OPTION
Description

Run COMMAND, ignoring hangup signals.

--help
display this help and exit
--version
output version information and exit
If standard input is a terminal, redirect it from /dev/null. If standard output is a terminal, append output to 'nohup.out' if possible, '$HOME/nohup.out' otherwise. If standard error is a terminal, redirect it to standard output. To save output to FILE, use 'nohup COMMAND > FILE'.

NOTE: your shell may have its own version of nohup, which usually supersedes the version described here. Please refer to your shell's documentation for details about the options it supports.

相关内容