shadowsocks / shadowsocks-libev

Bug-fix-only libev port of shadowsocks. Future development moved to shadowsocks-rust
https://github.com/shadowsocks/shadowsocks-rust
GNU General Public License v3.0
15.79k stars 5.69k forks source link

ss-local is failed to start as a Linux service on boot, if the "server" is a domain instead of a IP address. #2746

Closed StephenChips closed 3 years ago

StephenChips commented 4 years ago

Please answer these questions before submitting your issue. Thanks!

(Please mention that if the issue you filed is solved, you may wish to close it by yourself. Thanks again.)

(PS, you can remove 3 lines above, including this one, before post your issue.)

What version of shadowsocks-libev are you using?

3.3.4

What operating system are you using?

Ubuntu 20.04.1 LTS

What did you do?

Tried to auto-start shadowsocks after booting.

What did you expect to see?

Successfully boots ss-local, and I can use the proxy.

What did you see instead?

ss-local shut down.

What is your config in detail (with all sensitive info masked)?

Well, I configure a service to start ss-local once system booted. The configuration file is following:

[Unit]
Description=Shadowsocks Client Service

[Service]
User=root
Group=root
Type=simple
ExecStart=ss-local -c /etc/shadowsocks-libev/local.config.json -v start
ExecStep=ss-local -c /etc/shadowsocks-libeev/local.config.json -v stop

[Install]
WantedBy=multi-user.target

And my configuration file looks like following:

{
        "server": "<my server domain>",
        "server_port": 8388,
        "local_address": "127.0.0.1",
        "local_port": 1080,
        "password": "<my password>",
        "timout": 300,
        "method": "chacha20-ietf-poly1305",
        "fast_open": false,
        "plugin": "obfs-local",
        "plugin_opts": "obfs=http;obfs-host=<my-obfs-domain>"
}

When I filled in my server's domain in the "server" option, e.g.www.my-ss.site, The service cannot start successfully. Then, I typed systemctl status shadowsocks.service, and got following error:

● shadowsocks-local.service - Shadowsocks Client Service
     Loaded: loaded (/etc/systemd/system/shadowsocks-local.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Tue 2020-08-25 20:36:51 CST; 1min 57s ago
    Process: 853 ExecStart=/usr/bin/ss-local -c /etc/shadowsocks-libev/local.config.json -v start (code=exited, status=255/EXCEPTION)
   Main PID: 853 (code=exited, status=255/EXCEPTION)

Aug. 25 20:36:50 home-ubuntu systemd[1]: Started Shadowsocks Client Service.
Aug.  25 20:36:51 home-ubuntu ss-local[853]:  2020-08-25 20:36:51 ERROR: getaddrinfo: Temporary failure in name resolution
Aug.  25 20:36:51 home-ubuntu ss-local[853]:  2020-08-25 20:36:51 ERROR: failed to resolve the provided hostname
Aug.  25 20:36:51 home-ubuntu systemd[1]: shadowsocks-local.service: Main process exited, code=exited, status=255/EXCEPTION
Aug.  25 20:36:51 home-ubuntu systemd[1]: shadowsocks-local.service: Failed with result 'exit-code'.

Then I pinged the IP of my Shadowsocks's server, and replace the domain with it, restart the computer, and at the end, I found the service can start normally.

BTW, It is quite a odd that, when the "server" option was a domain, and if I typed systemctl start shadowsocks.service at the GUI's terminal window, it was able to start normally.

oakaigh commented 4 years ago

@StephenChips Add these lines to the [Unit] section to make your systemd service run after the network is up.

After=network-online.target
Wants=network-online.target

Let me know if this doesn't work.