fusenapi/stop_all_server.ps1

26 lines
897 B
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Function Stop-Server {
param (
[Parameter(Mandatory=$true)]
[string] $server_name
)
Write-Host "Stopping $server_name"
# 如果存在具有相同名称的 PowerShell Job将其终止
$existing_job = Get-Job -Name $server_name -ErrorAction SilentlyContinue
if ($null -ne $existing_job) {
Write-Host "Terminating job for $server_name"
Stop-Job -Name $server_name
Remove-Job -Name $server_name
}
else {
Write-Host "No job found for $server_name"
}
}
# 列出所有服务器目录
$server_dirs = "backend", "canteen", "data-transfer", "home-user-auth", "inventory", "map-library", "orders", "product", "product-model", "product-template", "shopping-cart-confirmation", "upload", "webset"
# 停止每个服务器的 PowerShell Job
foreach ($server_dir in $server_dirs) {
Stop-Server -server_name $server_dir
}