1

I am trying to set up an autossh service to forward ports to a remote server when my monitoring server boots. After some finagling, I got a pretty barebones system script working, with one catch. The service fails to properly start when it is run at boot, and yet works fine when started manually, or restarted immediately after reboot.

Description=AutoSSH tunnel service for Grafana to access mariadb on remote; local port 33060
After=network-online.target

[Service]
Environment="AUTOSSH_GATETIME=0"
ExecStart=/usr/bin/autossh -M 0 -N [email protected] -i /home/myuser/.ssh/id_rsa -o \"ServerAliveInterval 30\" -o \"ServerAliveCountMax 3\" -L 172.17.0.1:33307:127.0.0.1:3306

[Install]
WantedBy=multi-user.target

On boot, no connection is possible. The output from journalctl is something like:

-- 
-- The job identifier is 152.
Apr 07 15:25:31 monitoring autossh[752]: port set to 0, monitoring disabled
Apr 07 15:25:31 monitoring autossh[752]: starting ssh (count 1)
Apr 07 15:25:31 monitoring autossh[752]: ssh child pid is 759
Apr 07 15:25:31 monitoring autossh[759]: bind [172.17.0.1]:33307: Cannot assign requested address
Apr 07 15:25:31 monitoring autossh[759]: channel_setup_fwd_listener_tcpip: cannot listen to port: 33307
Apr 07 15:25:31 monitoring autossh[759]: Could not request local forwarding.

If I immediately sudo systemctl restart autossh-mariadb-tunnel.service, the connection works fine.

1 Answer 1

1

Shucks. Although I spent over an hour poring through questions and answers here and looking through duckduckgo results, the answer hit me as soon as I submitted the question. The clue is in the bind address: 172.17.0.1 is a docker interface. The problem is that I am listening on a docker interface but never told the script to wait for docker.

So, I revised line 2 to

After=network-online.target docker.service

and after a reboot, everything works as expected.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .