首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为autossh提供可靠的系统服务

为autossh提供可靠的系统服务
EN

Server Fault用户
提问于 2016-04-14 11:12:08
回答 1查看 2.5K关注 0票数 5

我试图为autossh创建一个可靠的systemd服务。

服务可以工作,但如果主机键更改,则服务处于状态ok (正在运行)。

如果隧道不起作用,我希望它处于“失败”状态。

下面是我当前的systemd服务文件:

代码语言:javascript
复制
# 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的输出

代码语言:javascript
复制
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服务文件以告诉我正确的状态?

更新:我写了第二个后续问题:系统如何决定服务是否正常?

EN

回答 1

Server Fault用户

发布于 2016-04-14 15:02:43

问题不是它失败了,而是它正在考虑服务活动,因为它将在接下来的10分钟内重新启动。

我没试过,但可能有用。尝试添加Type=forkingPIDFile

代码语言:javascript
复制
[Service]
...
Type=forking
Environment="AUTOSSH_PIDFILE=/path/to/pid"
PIDFile=/path/to/pid

使用simple服务,systemd在跟踪它们时可能会遇到问题。

票数 1
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/770281

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档