如何通过 SSH 控制 Upstart 会话作业?

如何通过 SSH 控制 Upstart 会话作业?

我有不少 Upstart 会话作业,其中包括启动 Tor、开发 Web 服务器等。initctl当我通过 GUI 登录系统时,我可以正常使用这些命令及其缩写。但是,通过 SSH,没有 Upstart 命令显示出哪怕一丁点知道会话作业的迹象。因此:

$ cat ~/.config/upstart/tor9050.conf
description "Tor on port 9050"
start on desktop-start
stop on session-end

respawn

expect daemon
exec /usr/sbin/tor -f /home/muru/.torrc9050
$ status tor9050
status: Unknown job: tor9050
$ pgrep -fa 9050
31096 /usr/sbin/tor -f /home/muru/.torrc9050

如您所见,会话作业运行良好,如果我登录到 GUI,status tor9050将显示预期的tor9050 start/running, process 31096输出。

那么:如何通过 SSH 获取 Upstart 会话作业的状态并以其他方式控制它?

答案1

我觉得有一种比较麻烦的方法,Upstart Cookbook(4.3.1.1:加入会议).您必须设置UPSTART_SESSION

export XDG_RUNTIME_DIR=/run/user/$(id -u)
export UPSTART_SESSION=$(initctl list-sessions | awk '{print $2; quit}')

之后,它运行正常:

$ status tor9050                                                             
tor9050 start/running, process 31096

相关内容