Skip to content

Instantly share code, notes, and snippets.

@valeryan valeryan/README.md
Last active Jun 17, 2020

Embed
What would you like to do?
WSL Startup Script

USAGE

  1. Save the services.sh file to your computer in a location like C:/tools/wsl-startup/.
  2. Download the WSL Statup.xml and import it into Task Scheduler.
  3. Modify as needed for you personal use.
#!/bin/bash
sudo service dbus start
sudo service cron start
sudo service atd start
sudo service memcached start
sudo service redis-server start
sudo service mysql start
sudo service php7.4-fpm start
sudo service nginx start
bash
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2020-03-16T14:14:50.2948542</Date>
<Author>DESKTOP-GV81FFD\samrh</Author>
<URI>\WSL Startup</URI>
</RegistrationInfo>
<Triggers>
<BootTrigger>
<Enabled>true</Enabled>
</BootTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>S-1-5-21-1767457005-3651416866-2414491648-1001</UserId>
<LogonType>S4U</LogonType>
<RunLevel>LeastPrivilege</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>Parallel</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>false</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
<UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>C:\Windows\System32\wsl.exe</Command>
<Arguments>sh /mnt/c/tools/wsl-startup/services.sh</Arguments>
</Exec>
</Actions>
</Task>
@codepuncher

This comment has been minimized.

Copy link

codepuncher commented Sep 20, 2018

You should just be able to set them to start on boot with:

sudo update-rc.d rsyslog defaults
sudo update-rc.d dbus defaults
sudo update-rc.d cron defaults
sudo update-rc.d atd defaults
sudo update-rc.d atd defaults
sudo update-rc.d dnsmasq defaults
sudo update-rc.d mysql defaults
sudo update-rc.d php7.2-fpm defaults
sudo update-rc.d nginx default
@valeryan

This comment has been minimized.

Copy link
Owner Author

valeryan commented Nov 27, 2018

I will test this in the latest wsl but I don't know that it supports modifying the run class.

@valeryan

This comment has been minimized.

Copy link
Owner Author

valeryan commented Nov 27, 2018

@codepuncher That does appear to work but any time you open additional bash windows it seems to create separate instances of the services in task manager. By having the services started by the script it only creates one instance of the services. Worth testing some more though. Thanks for the tip.

@kkm000

This comment has been minimized.

Copy link

kkm000 commented Dec 25, 2018

It is possible to launch WSL services with a Windows Task at logon. That decouples them from bash instances. The only trick, IIRC, is to allow the startup script to run without asking for a password in /etc/sudoers with a NOPASSWD: prefix.

Never tried the task at boot option, but maybe it can also work?

@hendrep

This comment has been minimized.

Copy link

hendrep commented Feb 23, 2019

I struggled with my pages sometimes loading and sometimes timing out.
I kept getting upstream timed out (110: Connection timed out) while reading upstream, client: 127.0.0.1, errors in my valet log.
As per this post, microsoft/WSL#393 (comment),
I added fastcgi_buffering off; to my site's Nginx config under .valet/Nginx.

Seemed to have solved my issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.