Skip to content

Commit 8d07aa2

Browse files
committed
feat: add emergency batch script
Errors will occurs when running `composer global update` without uninstalling valet first, because the services are still installed and therefore the files cannot be removed and updated since they're in-use. The batch script is to emergency stop and uninstall the services, and so a subsequent composer update is able to work. - Added the .bat file to stop and uninstall services. - Updated README to document this. - Added a copy command in `Configuration::install` method to copy the .bat file into the /.config/valet directory for safe keeping.
1 parent 2952086 commit 8d07aa2

3 files changed

Lines changed: 54 additions & 3 deletions

File tree

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ composer global require ycodetech/valet-windows
2222
2323
<br>
2424

25-
[Introduction](#introduction) | [Installation](#installation) | [Commands](#commands) | [Command Parity Checker](#command-parity-checker) | [Deprecations and Removals](#deprecations-and-removals) | [Known Issues](#known-issues) | [Xdebug Installation](#xdebug-installation) | [Contributions](#contributions)
25+
[Introduction](#introduction) | [Installation](#installation) | [Commands](#commands) | [Command Parity Checker](#command-parity-checker) | [Deprecations and Removals](#deprecations-and-removals) | [Emergency Stop and Uninstall Services](#emergency-stop-and-uninstall-services) | [Known Issues](#known-issues) | [Xdebug Installation](#xdebug-installation) | [Contributions](#contributions)
2626

2727
---
2828

@@ -334,6 +334,12 @@ This completely stops and uninstalls all of Valet's services.
334334

335335
You will also need to `uninstall` Valet if you are wanting to update Valet via Composer (`composer global update ycodetech/valet-windows`), just to make sure Composer can remove and update relevant files without error.
336336

337+
> [!CAUTION]
338+
>
339+
> If `composer global update` is ran before valet is uninstalled, then several running services may prevent composer from removing the files and updating valet.
340+
>
341+
> If this happens you can use the `emergency_uninstall_services.bat` file to stop and uninstall the services. See [Emergency Stop and Uninstall Services](#emergency-stop-and-uninstall-services) section.
342+
337343
###### --force
338344

339345
`--force` is to optionally force an uninstallation without Valet asking confirmation.
@@ -1464,6 +1470,20 @@ Doesn't affect valet functionality.
14641470
- cross = &#x2717;
14651471
-->
14661472
1473+
## Emergency Stop and Uninstall Services
1474+
1475+
As of v3.1.6, Valet has an emergency stop and uninstall services script. This script is copied to the `/.config/valet` directory for safe keeping.
1476+
1477+
So if `composer global update` is ran before valet is uninstalled, and several running services prevent composer from removing the files and updating valet, then you can run the `emergency_uninstall_services.bat` file to stop and uninstall the services.
1478+
1479+
To run, open a CMD terminal with Admin privileges and run this:
1480+
1481+
```sh
1482+
> %UserProfile%\.config\valet\emergency_uninstall_services.bat
1483+
```
1484+
1485+
All services will have been stopped and you can then be able to run `composer global update`.
1486+
14671487
## Known Issues
14681488

14691489
- WSL2 distros fail because of Acrylic DNS Proxy ([microsoft/wsl#4929](https://github.com/microsoft/WSL/issues/4929)). Use `valet stop`, start WSL2 then `valet start`.
@@ -1491,7 +1511,7 @@ Doesn't affect valet functionality.
14911511
14921512
> [!NOTE]
14931513
>
1494-
> Make sure you uninstall Valet before `composer global update`, to make sure all services have been stopped and uninstalled before composer removes and updates them.
1514+
> Make sure you uninstall Valet before `composer global update`, to make sure all services have been stopped and uninstalled before composer removes and updates them. Otherwise errors occur and composer can't update in-use files. If this does happen please refer to the [Emergency Stop and Uninstall Services](#emergency-stop-and-uninstall-services) section.
14951515
14961516
- If you're using a framework that uses a .env file and sets the domain name, such as `WP_HOME` for Laravel Bedrock, then make sure the TLD is the same as the one set for Valet. Otherwise, when trying to reach a site, the site will auto redirect to use the TLD in set in the .env.
14971517

cli/Valet/Configuration.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ public function install() {
3636
$this->createXdebugDirectory();
3737
$this->writeBaseConfiguration();
3838

39+
// Copy the emergency stop and uninstall services script to the Valet home
40+
// directory for safe keeping.
41+
$this->files->copy(
42+
realpath(__DIR__ . '/../../emergency_uninstall_services.bat'),
43+
$this->valetHomePath("emergency_uninstall_services.bat")
44+
);
45+
3946
$this->files->chown($this->path(), user());
4047
}
4148

@@ -468,4 +475,4 @@ public function path(): string {
468475
protected function valetHomePath(string $path = ''): string {
469476
return Valet::homePath($path);
470477
}
471-
}
478+
}

emergency_uninstall_services.bat

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@echo off
2+
3+
echo "Stopping and uninstalling all services..."
4+
5+
@REM Stop and uninstall Acrylic process
6+
echo Stopping AcrylicDNSProxySvc process...
7+
taskkill /fi "Services eq AcrylicDNSProxySvc" /F
8+
echo Uninstalling AcrylicDNSProxySvc process...
9+
sc delete AcrylicDNSProxySvc
10+
11+
@REM Stop nginx process
12+
echo Stopping nginx process...
13+
taskkill /IM nginx.exe /F
14+
15+
for /f %%f in ('dir /b /s "%UserProfile%\.config\valet\Services\*.exe"') do (
16+
@REM %%~dpnf is the path to the executable without the extension
17+
echo Stopping %%~dpnf...
18+
%%~dpnf stop
19+
20+
echo Uninstalling %%~dpnf...
21+
%%~dpnf uninstall
22+
)
23+
24+
echo "All services stopped and uninstalled."

0 commit comments

Comments
 (0)