Windows Subsystem for Linux, as of May 2018 still doesn't support init.d or systemd service management, and I ran into issues with services and several options online, with non working optimally for all cases
3 Answers
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 ; 3 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 startIf 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
This seems like nice automated hussle free method (at least to me)
I've not see any real good answers to this in the past so I developed the following script that I use on a few machines. It makes things like apt install apache2 much easier as its then typically automatically configured. I added comments to make it easier to know how to use it and threw it up on github. Also decided to fix an annoying visual bug.
This assumes that you have nopasswd in your sudoers file as otherwise you will get a prompt at startup.
#!/bin/bash
# Add new shortcut under the following directory
# "C:\Users\%USERNAME%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
# Make the shortcut here the following is an example, assuming this file is /etc/init.sh
# You can change the 3 to 5 for example if for example you used x11
# C:\Windows\System32\bash.exe -c "/usr/bin/sudo /etc/init.sh 3"
# You will also need to update your sudoers to allow NOPASSWD as otherwise it will prompt you for a password each time.
[[ -z $1 ]] && { echo "Need to specify a run level"; exit 127; }
run_level=$1
[[ -d /etc/rc${run_level}.d/ ]] || { echo "Need to specify a run level"; exit 127; }
for rc_service in /etc/rc${run_level}.d/K*; do [[ -e "$rc_service" ]] && $rc_service stop
done
for rc_service in /etc/rc${run_level}.d/S*; do [[ -e "$rc_service" ]] && $rc_service start
doneI'll take any bug fixes or suggestions here: