4

Postgres server on Debian should run on Windows 11 boot.

Debian was installed using

wsl --install Debian

Postgres in Debian using

sudo apt install postgresql-12

Created /etc/wsl.conf as described in this answer:

[boot]
command="service postgresql start"

Created task scheduler task which runs on startup. Tried to run commands from it

wsl

and

wsl -u root 

I tried to run VB script from here:

set object = createobject("wscript.shell") 
object.run "wsl.exe", 0

However WSL and Postgres and are not started if Windows is re-booted.

Solutions in this answer seem to be outdated since /etc/wsl.conf should used to run daemons in WSL.

If VBS script is run from command line, Postgres server is started.

How to run Debian/Postgres as service in Windows 11 boot? Should SrvAny, NSSM or Startup Scheduled Task used?

wsl --version returns

Verze WSL: 1.0.3.0
Verze jádra: 5.15.79.1
Verze WSLg: 1.0.47
Verze MSRDC: 1.2.3575
Verze Direct3D: 1.606.4
Verze DXCore: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
verze Windows: 10.0.22621.1105
NotTheDr01ds
  • 28,025
Andrus
  • 253

3 Answers3

3

It appears that Microsoft broke the capability of starting WSL as a service or a scheduled task when is was moved to their store because it will no longer run in session 0.

These conclusions can be inferred from the discussions with Microsoft's Windows Subsystem for Linux teams found on here on github.

Makes it less useful for sure. Only info from MS is they are working on it. Whether they are remains to be seen.

Geeky51
  • 131
2

You can create a batch-file like e.g. startWsl2Services.bat in the shell:startup folder (Win-R, type shell:startup):

@echo off
echo "Starting Ubuntu-22.04..."
wsl -d Ubuntu-22.04 -u root service dbus start
echo "Done"

or whichever distro (in your case Debian) and service you want to get started after user login

daboss
  • 23
  • 4
0

Auto start WSL on boot can keep it alive in the background can be done with help of nssm. Check out this comment in a WSL issue thread.

  • install NSSM

  • run nssm install wsl, and write this stuff:

enter image description here

  • go to log on, and select "this account", get your username by typing whoami in another terminal if you dont know ur proper username, and put in your password u use to login too.

  • click save button, and then run nssm start wsl

oeter
  • 334