Jump to content

Systemd equivalent for autossh demon?


Recommended Posts

On my Debian based servers, I use systemd to make sure my reverse SSH tunnel starts at boot and make sure it's running. Now I want to do similar to my Unraid server.

 

What is the equivalent to this file

[Unit]
Description=My AutoSSH tunnel service
After=network.target

[Service]
Environment="AUTOSSH_GATETIME=0"
ExecStart=/usr/bin/autossh -M 0 -o ServerAliveInterval=60 -o ServerAliveCountMax=3 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -NTi /etc/ssh/id_ed25519 -R 1234:localhost:22 [email protected]

[Install]
WantedBy=multi-user.target

?

Edited by walle
Typo in codesnippet
Link to comment

/config/go.txt is a startup script for unraid, if all you want is trigger something on every boot

 

The user scripts plugin also allows you to schedule scripts at various triggers and events - like cron, array start / stop etc.

Further, what you want to do might be possible via a docker container which can be set to auto start with array

Link to comment

Thank you for your rely Apandey.

 

Currently I have this bottom of the go-file:

# Autossh relay
/usr/bin/autossh -M 0 -o ServerAliveInterval=60 -o ServerAliveCountMax=3 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -NTfi /etc/ssh/id_ed25519 -R 1234:localhost:22 [email protected]

 

The thing is autossh instance sometimes dies without any apparent reason. I have seen behavior for a few of my other servers where I have initiated autossh with a cronjob. This is quite worrisome for me sense this may be the only way I can remotely connect to the server.  The other servers I have runs autossh with systemd have worked flawlessly.

 

This is why I want to run autossh  as a service/demon or whatever else that is similar to systemd and that works even if the array haven't started. So I don't think either user scripts or Docker based solutions will not work for me.

Link to comment

My use case is my Unraid server is behind a CG-NAT, aka. the public IP number is shared, so it isn't possible to SSH to the server directly over the internet. The workaround I have for this is to let the server connect via a tunnel to a VPS. When I need to access my server remotely, I do a reverse tunnel connection via the VPS to my server. In other words, If the tunnel goes down, I can no longer access the server.

 

In order to keep the tunnel alive, I currently use autossh and trigger it in the GO-file. But this doesn't seem to be enough, sense I have seen autossh process die time to time. So I need some kind of solution that can monitor autossh and restart it when needed. I don't think, as far as I know, either cron or user scripts plugin can do that.

 

In regards to Docker, it's normally my go-to solution to solve most of my problems and could maybe partly solves the issue with health checks. But I don't think it's a good fit in this case for two reasons. First of all, I don't want to SSH into the container and I think there is no good way to "break out" from it in order to access the host. Second, Docker will not run unless the array have started. I need to have remote access to server even if the array goes down or the array can't start for some reason.

Edited by walle
Clerefying CG-NAT and typo.
Link to comment

Humm, good idea. My router is a Unifi console and maybe possible to run autossh with a demon on that. Otherwise my plan B is to run a Raspberry PI with Rasbian + autossh and use the configuration I mentioned in my first post. In case of autossh fails on my Unraid server, I can still login via the pi to the network.

Link to comment
On 4/26/2023 at 8:58 AM, JonathanM said:

Perhaps it would be better to build a lightweight PC based router with your tunnel and failsafes built in so your whole network is available with the proper firewall rules

That is what I have, pfSense with VPN server. All network security happens here and availability is not a concern due to focused application. Unraid is then just another appliance on the inside then 

Link to comment

I looked into if it was possible to run autossh as a demon on my Unifi console, it seems to not be possible (without do a bunch of hacky stuff). :(

 

Put a Raspberry PI on the network is most likely workaround I will probably do if it can't be solved with Unraid.

Edited by walle
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...