Today I was trying to set up my WSL Ubuntu's Nginx web server to automatically start on Windows 10 boot-up.
I had previously been loading my WSL Ubuntu terminal, running sudo su - to switch to root, then running /var/www/global/Set_Permissions; service php7.4-fpm start; service nginx start; logout. This keeps my Nginx service running fine until I reboot my Windows 10, even after I log out of my WSL terminal.
I tried the advice from this post:
How to make WSL run services at startup
I added my startup commands to /etc/wsl.conf and rebooted Windows 10, logged into my user, loaded up my web browser -- and great, I could view my internal Nginx web sites. However, about 30 seconds later, the WSL Ubuntu background service turned off, and my web sites wouldn't load anymore.
Doing some investigation, I have determined that simply loading my WSL Ubuntu terminal will start the service up again. But, if I close the terminal and wait around 30 seconds, the Nginx service is stopped and I can't load my web sites!
So clearly the linked solution does not actually work in my situation, as it requires a WSL Ubuntu terminal to remain open indefinitely. My previous solution of sudo su - and running the command manually is a lot better, because it actually works.
How can I run services in my WSL Ubuntu on Windows 10 startup so they will not shut down when my WSL terminal isn't open?
Also, why will my service stop running when started from /etc/wsl.conf, but keeps running when started from an interactive Bash shell?
It seems that every time I load my terminal it reruns the commands in /etc/wsl.conf, then after a few seconds of the terminal not being open, it shuts down WSL again, to repeat the next time I open my WSL terminal. I only want the commands to run one time when my Windows 10 computer boots up, not every time I load a WSL terminal.