如何使用systemd> 230运行tmux / screen?

我运行16.04并且systemd现在在用户断开连接时杀死tmux ( 更改摘要 )。

有没有办法用systemd 230运行tmuxscreen (或任何类似的程序)? 我阅读了所有关于行为的利弊的激烈讨论,但没有提出任何解决方案。

(我也看到了229中的行为)

RemainAfterExit =

采用一个布尔值,指定即使退出所有进程,服务是否应被视为活动状态。 默认为否。

正确的解决方案是在系统范围内禁用违规系统行为。

编辑/etc/systemd/logind.conf (当然你必须sudo )并设置

 KillUserProcesses=no 

您也可以将此设置放在单独的文件中,例如/etc/systemd/logind.conf.d/99-dont-kill-user-processes.conf

然后重新启动systemd-logind.service

 sudo systemctl restart systemd-logind 

基于@Rinzwind的回答并受到单元描述的启发,我能找到的最好的是使用TaaS(Tmux即服务) – 一个重新连接的tmux的通用分离实例。

 # cat /etc/systemd/system/tmux@.service [Unit] Description=tmux default session (detached) Documentation=man:tmux(1) [Service] Type=oneshot RemainAfterExit=yes ExecStart=/usr/bin/tmux new-session -d -s %I ExecStop=/usr/bin/tmux kill-server KillMode=none [Install] WantedBy=multiplexer.target # systemctl start tmux@instanceone.service # systemctl start tmux@instancetwo.service # tmux list-sessions instanceone: 1 windows (created Sun Jul 24 00:52:15 2016) [193x49] instancetwo: 1 windows (created Sun Jul 24 00:52:19 2016) [193x49] # tmux attach-session -t instanceone (instanceone)# 

您需要将服务Type设置为forking ,如此处所述。

让我们假设您想要在screen运行的服务称为minecraft 。 然后,您将在文本编辑器中打开minecraft.service ,并在[Service]部分下添加或编辑条目Type=forking

根据https://unix.stackexchange.com/a/287282/117599调用tmux使用

 systemd-run --user --scope tmux 

也应该做的伎俩。