问题描述
我们正在尝试让 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
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 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!