我在 Mac (Mavericks) 上通过由 launchd 控制的 bash shell 脚本运行 autossh。不幸的是,我设置的方式会导致 autossh 产生数十个自身和 ssh 的实例。最终,shell 似乎停止运行,远程连接变得不可能。如果我将 autossh 和 ssh 都杀掉,一切都会恢复正常。
这在主机上:
Axe:~ mnewman$ ps -A | grep -c -w ssh
41
Axe:~ mnewman$ ps -A | grep -c -w autossh
152
这在客户端:
MrMuscle:~ mnewman$ ssh -p19990 mnewman@localhost
Last login: Sat Jul 6 16:19:50 2019 from localhost
-bash: fork: Resource temporarily unavailable
-bash-3.2$
我花了很长时间才开始运行它。到目前为止,我还不知道如何弄清楚这里发生了什么。
外壳脚本:
#!/bin/bash
/opt/local/bin/autossh -f -M 0 -N -o ExitOnForwardFailure=yes -o ServerAliveInterval=30 -o ServerAliveCountMax=2 -R 19990:localhost:22 mnewman@korat.myddns.rocks -p 10000
~/Library/LaunchAgents 中的launchd plist 文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Debug</key>
<false/>
<key>Disabled</key>
<false/>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
</string>
</dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>com.mgnewman.autossh</string>
<key>ProgramArguments</key>
<array>
<string>/Users/mnewman/bin/autossh.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/Users/mnewman/Desktop/autossh.txt</string>
<key>StandardOutPath</key>
<string>/Users/mnewman/Desktop/autossh.txt</string>
<key>WorkingDirectory</key>
<string>/Users/mnewman/Documents</string>
</dict>
</plist>
我在这里做了什么来产生这么多 autossh 和 ssh 的实例?