Autossh script running as systemctl start SERVICE works but systemctl enable SERVICE failed

送分小仙女□ 提交于 2021-02-10 16:16:54

问题


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.


回答1:


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

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



来源:https://stackoverflow.com/questions/43178713/autossh-script-running-as-systemctl-start-service-works-but-systemctl-enable-ser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!