Back to Article List

Fix Hermes WSL2 gateway disconnecting on Windows

Fix Hermes WSL2 gateway disconnecting on Windows

You install Hermes Agent inside WSL2, run hermes gateway start, connect Telegram, all working. You close the terminal. Come back later. Gateway is dead. WSL killed the distro because nothing was running in it.

This is the most-asked Windows-specific Hermes question. WSL2's lifecycle is designed to save memory by shutting down idle distros. Hermes didn't sign up for that. Three patterns keep the gateway running. Pick the one that matches how you use the machine.

Why this happens

WSL2 distros aren't always-on like a real VM. The distro starts when a terminal needs it. It stops when no terminal session is using it, after a short grace period. Microsoft's design choice: save RAM when not in use.

The flip side: anything running inside the distro (Hermes gateway, cron jobs, background services) dies with the distro. systemd inside WSL2 doesn't help with this; systemd manages the gateway right up until WSL pulls the rug from underneath.

Pattern 1: Keep the distro alive with a hidden process

The simplest fix. Run a long-running process inside the distro that WSL counts as "active":

wsl -d Ubuntu-24.04 --exec bash -c "while true; do sleep 3600; done" &

That's a Windows command (run in PowerShell) that starts a sleep loop inside Ubuntu without a visible terminal. WSL sees an active process and keeps the distro running. Hermes gateway inside the distro stays alive too.

Make it persistent across reboots via Task Scheduler

  1. Press Win+R, type taskschd.msc, Enter
  2. Action menu > Create Task
  3. General tab: name it "Hermes WSL keepalive"
  4. Triggers tab: New > Begin the task: At log on
  5. Actions tab: New > Start a program > Program: wsl > Arguments: -d Ubuntu-24.04 --exec bash -c "while true; do sleep 3600; done"
  6. Settings tab: uncheck "Stop the task if it runs longer than"
  7. OK

From next Windows login, the distro stays alive automatically. Gateway stays up with it.

Pattern 2: tmux as the foreground holder

This is what I prefer because the gateway runs visibly and I can attach to it any time to read logs.

sudo apt install tmux
tmux new -s hermes -d "hermes gateway start"

Detach is automatic. tmux runs the gateway as a backgrounded session.

Attach later to check on it

tmux attach -t hermes

Detach with Ctrl+B then D.

This still needs the distro to stay alive

tmux on its own only prevents your terminal from killing the gateway. It doesn't prevent WSL from shutting down the distro when no terminals exist. Combine pattern 2 with pattern 1 or pattern 3.

Pattern 3: Native Windows service wrapping wsl --exec

The most robust option. Windows becomes responsible for keeping the gateway running, with proper restart policies and logging.

The tool I use is NSSM (Non-Sucking Service Manager). Install via chocolatey or download the binary, then:

nssm install HermesGateway "C:\Windows\System32\wsl.exe" "-d Ubuntu-24.04 --exec /home/youruser/.local/bin/hermes gateway start --foreground"
nssm set HermesGateway AppStdout C:\HermesLogs\stdout.log
nssm set HermesGateway AppStderr C:\HermesLogs\stderr.log
nssm set HermesGateway Start SERVICE_AUTO_START
nssm start HermesGateway

What this gives you

Service starts at boot. Restarts if it crashes. Logs to files you can tail in PowerShell. WSL stays alive because Windows is keeping a process active in it. Gateway stays up because NSSM is restarting it on failure.

The --foreground flag tells Hermes not to daemonise. NSSM needs the process it manages to stay foreground or it can't track it properly.

About systemd inside WSL2

Recent WSL2 supports systemd if you opt in. Edit /etc/wsl.conf and add:

[boot]
systemd=true

Then wsl --shutdown from PowerShell and re-open the distro. systemd is now running.

Why systemd alone isn't enough

systemd inside WSL is happy to manage and restart the gateway. But systemd cannot prevent WSL itself from stopping. When WSL goes down, systemd goes with it.

What systemd does add: clean restarts after crashes, proper log management via journalctl, ability to apply hardening flags. Enable it. But pair it with pattern 1 or pattern 3 to keep the outer distro alive.

systemd unit file pattern in our Hermes Agent systemd setup tutorial.

Troubleshooting each pattern

Pattern 1 issues

The keepalive process is invisible and easy to forget about. If you forget you set it up and wonder why the distro never shuts down, that's why. To check:

wsl --list --running
schtasks /query /tn "Hermes WSL keepalive"

Pattern 2 issues

If WSL goes down (reboot, manual wsl --shutdown), tmux dies with it. You need pattern 1 or pattern 3 to bring everything back automatically.

Pattern 3 issues

NSSM service runs as a specific Windows user. WSL path references need to resolve for that user. If you set up NSSM under your account and a different Windows user logs in, the service might run in the wrong context. Less common but worth knowing.

The bigger trade-off

WSL2 is the right path for Windows devs who want a Linux CLI. It is not the right path for hosting a 24/7 gateway. Every pattern above is a workaround for WSL doing the thing it's designed to do: shut down idle distros.

If your gateway needs to be reliably up, run the agent on a Linux VPS and use Hermes Desktop or WebUI as your Windows interface. Our Hermes Desktop remote backend on VPS covers the hybrid pattern. VPS doesn't care if your laptop is closed or on a different continent.

If the gateway was working but suddenly disconnected

Three usual causes:

  • Windows update changed WSL keepalive behaviour
  • WSL update changed it
  • Your keepalive process died (Task Scheduler disabled, reboot without auto-start kicking in)

Check:

wsl --status
wsl --list --running
schtasks /query /tn "Hermes WSL keepalive"

If the distro isn't running and the keepalive task isn't running, that's the cause. Re-enable and restart WSL.

Move the gateway to a VPS

If you're spending more time keeping the gateway up than using it, the LumaDock Hermes Agent template gives you a Linux VPS with the agent ready to run. Laptop becomes a client, not a host. Unmetered bandwidth and no setup fees. Full setup in our Hermes Agent complete guide.

Your idea deserves better hosting

24/7 support 30-day money-back guarantee Cancel anytime
Verrechnungszyklus

1 GB RAM VPS

£2.98 Save  25 %
£2.23 Monatlich
  • 1 vCPU AMD EPYC
  • 30 GB NVMe Speicher
  • Unbegrenzte Bandbreite
  • IPv4 & IPv6 inklusive IPv6-Unterstützung ist derzeit in Frankreich, Finnland und den Niederlanden nicht verfügbar.
  • 1 Gbps Netzwerk
  • Firewall-Verwaltung
  • Server-Überwachung

2 GB RAM VPS

£4.47 Save  17 %
£3.72 Monatlich
  • 2 vCPU AMD EPYC
  • 30 GB NVMe Speicher
  • Unbegrenzte Bandbreite
  • IPv4 & IPv6 inklusive IPv6-Unterstützung ist derzeit in Frankreich, Finnland und den Niederlanden nicht verfügbar.
  • 1 Gbps Netzwerk
  • Firewall-Verwaltung
  • Server-Überwachung

6 GB RAM VPS

£11.18 Save  33 %
£7.45 Monatlich
  • 6 vCPU AMD EPYC
  • 70 GB NVMe Speicher
  • Unbegrenzte Bandbreite
  • IPv4 & IPv6 inklusive IPv6-Unterstützung ist derzeit in Frankreich, Finnland und den Niederlanden nicht verfügbar.
  • 1 Gbps Netzwerk
  • Firewall-Verwaltung
  • Server-Überwachung

AMD EPYC VPS.P1

£5.96 Save  25 %
£4.47 Monatlich
  • 2 vCPU AMD EPYC
  • 4 GB RAM-speicher
  • 40 GB NVMe speicher
  • Unbegrenzte Bandbreite
  • IPv4 & IPv6 inklusive IPv6-Unterstützung ist derzeit in Frankreich, Finnland und den Niederlanden nicht verfügbar.
  • 1 Gbps Netzwerk
  • Auto-Backup enthalten
  • Firewall-Verwaltung
  • Server-Überwachung

AMD EPYC VPS.P2

£11.18 Save  27 %
£8.20 Monatlich
  • 2 vCPU AMD EPYC
  • 8 GB RAM-speicher
  • 80 GB NVMe speicher
  • Unbegrenzte Bandbreite
  • IPv4 & IPv6 inklusive IPv6-Unterstützung ist derzeit in Frankreich, Finnland und den Niederlanden nicht verfügbar.
  • 1 Gbps Netzwerk
  • Auto-Backup enthalten
  • Firewall-Verwaltung
  • Server-Überwachung

AMD EPYC VPS.P4

£22.38 Save  20 %
£17.90 Monatlich
  • 4 vCPU AMD EPYC
  • 16 GB RAM-speicher
  • 160 GB NVMe speicher
  • Unbegrenzte Bandbreite
  • IPv4 & IPv6 inklusive IPv6-Unterstützung ist derzeit in Frankreich, Finnland und den Niederlanden nicht verfügbar.
  • 1 Gbps Netzwerk
  • Auto-Backup enthalten
  • Firewall-Verwaltung
  • Server-Überwachung

AMD EPYC VPS.P5

£27.23 Save  21 %
£21.63 Monatlich
  • 8 vCPU AMD EPYC
  • 16 GB RAM-speicher
  • 180 GB NVMe speicher
  • Unbegrenzte Bandbreite
  • IPv4 & IPv6 inklusive IPv6-Unterstützung ist derzeit in Frankreich, Finnland und den Niederlanden nicht verfügbar.
  • 1 Gbps Netzwerk
  • Auto-Backup enthalten
  • Firewall-Verwaltung
  • Server-Überwachung

AMD EPYC VPS.P6

£42.52 Save  21 %
£33.57 Monatlich
  • 8 vCPU AMD EPYC
  • 32 GB RAM-speicher
  • 200 GB NVMe speicher
  • Unbegrenzte Bandbreite
  • IPv4 & IPv6 inklusive IPv6-Unterstützung ist derzeit in Frankreich, Finnland und den Niederlanden nicht verfügbar.
  • 1 Gbps Netzwerk
  • Auto-Backup enthalten
  • Firewall-Verwaltung
  • Server-Überwachung

AMD EPYC VPS.P7

£52.22 Save  20 %
£41.78 Monatlich
  • 16 vCPU AMD EPYC
  • 32 GB RAM-speicher
  • 240 GB NVMe speicher
  • Unbegrenzte Bandbreite
  • IPv4 & IPv6 inklusive IPv6-Unterstützung ist derzeit in Frankreich, Finnland und den Niederlanden nicht verfügbar.
  • 1 Gbps Netzwerk
  • Auto-Backup enthalten
  • Firewall-Verwaltung
  • Server-Überwachung

EPYC Genoa VPS.G1

£3.72 Save  20 %
£2.98 Monatlich
  • 1 vCPU AMD EPYC Gen4 AMD EPYC Genoa der 4. Generation 9xx4 mit 3,25 GHz oder ähnlich, basierend auf der Zen 4 Architektur.
  • 1 GB DDR5 RAM-speicher
  • 25 GB NVMe speicher
  • Unbegrenzte Bandbreite
  • IPv4 & IPv6 inklusive IPv6-Unterstützung ist derzeit in Frankreich, Finnland und den Niederlanden nicht verfügbar.
  • 1 Gbps Netzwerk
  • Auto-Backup enthalten
  • Firewall-Verwaltung
  • Server-Überwachung

EPYC Genoa VPS.G2

£9.69 Save  23 %
£7.45 Monatlich
  • 2 vCPU AMD EPYC Gen4 AMD EPYC Genoa der 4. Generation 9xx4 mit 3,25 GHz oder ähnlich, basierend auf der Zen 4 Architektur.
  • 4 GB DDR5 RAM-speicher
  • 50 GB NVMe speicher
  • Unbegrenzte Bandbreite
  • IPv4 & IPv6 inklusive IPv6-Unterstützung ist derzeit in Frankreich, Finnland und den Niederlanden nicht verfügbar.
  • 1 Gbps Netzwerk
  • Auto-Backup enthalten
  • Firewall-Verwaltung
  • Server-Überwachung

EPYC Genoa VPS.G4

£19.39 Save  27 %
£14.17 Monatlich
  • 4 vCPU AMD EPYC Gen4 AMD EPYC Genoa der 4. Generation 9xx4 mit 3,25 GHz oder ähnlich, basierend auf der Zen 4 Architektur.
  • 8 GB DDR5 RAM-speicher
  • 100 GB NVMe speicher
  • Unbegrenzte Bandbreite
  • IPv4 & IPv6 inklusive IPv6-Unterstützung ist derzeit in Frankreich, Finnland und den Niederlanden nicht verfügbar.
  • 1 Gbps Netzwerk
  • Auto-Backup enthalten
  • Firewall-Verwaltung
  • Server-Überwachung

EPYC Genoa VPS.G6

£36.55 Save  31 %
£25.36 Monatlich
  • 8 vCPU AMD EPYC Gen4 AMD EPYC Genoa der 4. Generation 9xx4 mit 3,25 GHz oder ähnlich, basierend auf der Zen 4 Architektur.
  • 16 GB DDR5 RAM-speicher
  • 200 GB NVMe speicher
  • Unbegrenzte Bandbreite
  • IPv4 & IPv6 inklusive IPv6-Unterstützung ist derzeit in Frankreich, Finnland und den Niederlanden nicht verfügbar.
  • 1 Gbps Netzwerk
  • Auto-Backup enthalten
  • Firewall-Verwaltung
  • Server-Überwachung

EPYC Genoa VPS.G7

£55.95 Save  27 %
£41.03 Monatlich
  • 8 vCPU AMD EPYC Gen4 AMD EPYC Genoa der 4. Generation 9xx4 mit 3,25 GHz oder ähnlich, basierend auf der Zen 4 Architektur.
  • 32 GB DDR5 RAM-speicher
  • 250 GB NVMe speicher
  • Unbegrenzte Bandbreite
  • IPv4 & IPv6 inklusive IPv6-Unterstützung ist derzeit in Frankreich, Finnland und den Niederlanden nicht verfügbar.
  • 1 Gbps Netzwerk
  • Auto-Backup enthalten
  • Firewall-Verwaltung
  • Server-Überwachung

AMD Ryzen VPS.R1

£11.93 Save  31 %
£8.20 Monatlich
  • 1 dedizierter CPU AMD Ryzen 9 7950X mit 4,5 GHz oder ähnlich, auf Zen 4-Architektur. vCPU
  • 4 GB DDR5RAM
  • 50 GB NVMeSPEICHER
  • Unbegrenzter Traffic
  • IPv4 & IPv6 inklusive IPv6-Support ist derzeit nicht verfügbar in Frankreich, Finnland oder den Niederlanden.
  • Auto-Backup inklusive

AMD Ryzen VPS.R2

£20.88 Save  21 %
£16.41 Monatlich
  • 2 dedizierte CPUs AMD Ryzen 9 7950X mit 4,5 GHz oder ähnlich, auf Zen 4-Architektur. vCPU
  • 8 GB DDR5RAM
  • 100 GB NVMeSPEICHER
  • Unbegrenzter Traffic
  • IPv4 & IPv6 inklusive IPv6-Support ist derzeit nicht verfügbar in Frankreich, Finnland oder den Niederlanden.
  • Auto-Backup inklusive

AMD Ryzen VPS.R4

£74.61 Save  20 %
£59.68 Monatlich
  • 8 dedizierte CPUs AMD Ryzen 9 7950X mit 4,5 GHz oder ähnlich, auf Zen 4-Architektur. vCPU
  • 32 GB DDR5RAM
  • 400 GB NVMeSPEICHER
  • Unbegrenzter Traffic
  • IPv4 & IPv6 inklusive IPv6-Support ist derzeit nicht verfügbar in Frankreich, Finnland oder den Niederlanden.
  • Auto-Backup inklusive

FAQ

How do I keep WSL2 running even when no terminal is open?

Start a long-running process inside the distro that WSL counts as active. Run wsl --exec bash -c "while true; do sleep 3600; done" in PowerShell, optionally via Task Scheduler on login.

Your agent runs wild. Your bill doesn't.

Easily deploy Hermes in one click on Ubuntu 24.04 with AMD EPYC, NVMe storage and unmetered bandwidth. The price stays the same whatever the agent does, no setup fees, no overage charges and no tier traps.

GPU products are in high demand at the moment. Fill the form to get notified as soon as your preferred GPU server is back in stock.