我试图为autossh创建一个可靠的systemd服务。
服务可以工作,但如果主机键更改,则服务处于状态ok (正在运行)。
如果隧道不起作用,我希望它处于“失败”状态。
下面是我当前的systemd服务文件:
# Source is in srv/salt/tunnel/autossh\@.service
# which is a git repo.
# Don't edit /etc/systemd/system/autossh\@.service
[Unit]
Description=Tunnel For %i
After=network.target
[Service]
User=autossh
# https://serverfault.com/a/563401/90324
ExecStart=/usr/bin/autossh -M 0 -N -o "ExitOnForwardFailure yes" -o "ConnectTimeout=1" -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -R 40443:installserver:40443 -R 8080:installserver:8080 tunnel@%i
Restart=always
[Install]
WantedBy=multi-user.target这是systemctl status autossh@foo-work的输出
salt:/srv # systemctl status autossh@foo-work
autossh@foo-work.service - Tunnel For foo-work
Loaded: loaded (/etc/systemd/system/autossh@.service; enabled)
Active: active (running) since Wed, 2016-02-10 14:35:01 CET; 2 months and 3 days ago
Main PID: 17995 (autossh)
CGroup: name=systemd:/system/autossh@.service/foo-work
└ 17995 /usr/bin/autossh -M 0 -N -o ExitOnForwardFailure yes -o ConnectTimeout=1 -o ServerAliveInterval 60 -o ServerAliveCountMax 3 -R 40443:installserver:40443 -R ...
Apr 14 12:35:43 salt autossh[17995]: Host key verification failed.
Apr 14 12:35:43 salt autossh[17995]: ssh exited with error status 255; restarting ssh
Apr 14 12:45:42 salt autossh[17995]: starting ssh (count 618)
Apr 14 12:45:42 salt autossh[17995]: ssh child pid is 22524
Apr 14 12:45:43 salt autossh[17995]: Host key verification failed.
Apr 14 12:45:43 salt autossh[17995]: ssh exited with error status 255; restarting ssh我的问题不是改变了主机键。没关系。
我只想让服务告诉我真相:如果隧道不工作,那么我想让它看到它。
如何更改systemd服务文件以告诉我正确的状态?
更新:我写了第二个后续问题:系统如何决定服务是否正常?。
发布于 2016-04-14 15:02:43
问题不是它失败了,而是它正在考虑服务活动,因为它将在接下来的10分钟内重新启动。
我没试过,但可能有用。尝试添加Type=forking和PIDFile
[Service]
...
Type=forking
Environment="AUTOSSH_PIDFILE=/path/to/pid"
PIDFile=/path/to/pid使用simple服务,systemd在跟踪它们时可能会遇到问题。
https://serverfault.com/questions/770281
复制相似问题