作为 systemctl start SERVICE 运行的 Autossh 脚本有效,但 systemctl enable SERVICE 失败 [英] Autossh script running as systemctl start SERVICE works but systemctl enable SERVICE failed

查看:41
本文介绍了作为 systemctl start SERVICE 运行的 Autossh 脚本有效,但 systemctl enable SERVICE 失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试让 autossh 在 Ubuntu 16.04.2 启动时连接到远程服务器.所以我们使用 systemctl 来完成这项工作.脚本如下:

[单位]说明=保持通往远程服务器"的隧道打开之后=网络.目标[服务]ExecStart=/usr/bin/autossh -NR 83232:localhost:22 -i/home/user/.ssh/id_rsa REMOTE_USER@REMOTE_IP[安装]WantedBy=multi-user.target

如果我们使用 start 启动服务就可以了

systemctl start SERVICE

但是如果我们使用启用服务会失败

systemctl enable SERVICE

错误代码是

<块引用>

ssh:连接到主机 REMOTE_IP 端口 22:网络无法访问"

有人可以提供任何建议吗?

非常感谢.

解决方案

使用 After=network-online.target 代替 After=network.target.>

systemd wiki 页面上记录了有关 systemd 网络目标的更多信息.

We are trying to get autossh to connect to remote server at boot time in Ubuntu 16.04.2. So we use systemctl to do the job. The script is as following:

[Unit]
Description=Keeps a tunnel to 'remote server' open
After=network.target

[Service]
ExecStart=/usr/bin/autossh -NR 83232:localhost:22 -i /home/user/.ssh/id_rsa REMOTE_USER@REMOTE_IP

[Install]
WantedBy=multi-user.target

It would work fine if we start the service by using start

systemctl start SERVICE

But it would fail if we use enable service

systemctl enable SERVICE

The error code is

"ssh: connect to host REMOTE_IP port 22: Network is unreachable"

Can anybody offer any advices?

Many thanks.

解决方案

Instead of After=network.target, use After=network-online.target.

More about systemd network targets are documented on the systemd wiki page.

这篇关于作为 systemctl start SERVICE 运行的 Autossh 脚本有效,但 systemctl enable SERVICE 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆