How to run init.d scripts on Windows WSL?
Solution 1:
The following bash script works for me.. Note the continue
operator is needed to skip scripts that fail, and the start
argument is needed by most service scripts.. i believe
for f in /etc/init.d/*; do sh "$f" start || continue; done ;
Solution 2:
This is just a general direction (it is how I did it) - maybe someone can improve the idea.
Whenever LxssManager service is started (restarted) there are 2 entries in Event Viewer -> Windows Logs -> Security
Audit Success Sun 13.01.2019 13:34:52 Microsoft Windows security auditing. 4672 Special Logon Audit Success Sun 13.01.2019 13:34:52 Microsoft Windows security auditing. 4624 Logon
If you right click the one with "Special logon" in task category column you can "Attach task to this event" with folowing actions (using Task Scheduler)
Program/script: C:\Windows\System32\wsl.exe and with Arguments: /usr/bin/apache.sh (or any other .sh file you have created)
On the linux side create .sh file to start your service within Linux (this is how I did it):
create apache.sh and put it into /usr/bin/
My apache.sh looks like:
#!/bin/sh
sudo service apache2 start
If your script requires linux authentication you can use
ubuntu config --default-user root (will set default user as root ) - run this from cmd.exe with admin privileges.
For more on this https://docs.microsoft.com/en-us/windows/wsl/user-support
This seems like nice automated hussle free method (at least to me)