尝试提交一个 兼容windows版本的 shell

This commit is contained in:
eson 2023-07-19 12:12:27 +08:00
parent a62b8692f5
commit 52d3767256
2 changed files with 60 additions and 0 deletions

34
run_all_server.ps1 Normal file
View File

@ -0,0 +1,34 @@
Function Run-Server {
param (
[Parameter(Mandatory=$true)]
[string] $server_name
)
Write-Host "Running $server_name"
# 导航到相应的目录
Set-Location -Path "server/$server_name"
# 使用 PowerShell Jobs 运行 go run <server_name>.go
Start-Job -Name $server_name -ScriptBlock { go run $server_name.go }
# 返回到上一级目录
Set-Location -Path ".."
}
# 列出所有服务器目录
$server_dirs = "backend", "canteen", "data-transfer", "home-user-auth", "inventory", "map-library", "orders", "product", "product-model", "product-template", "shopping-cart-confirmation", "upload", "webset"
# 在每个服务器目录下运行相应的 go 程序
foreach ($server_dir in $server_dirs) {
Run-Server -server_name $server_dir
}
# 定义目录和screen名称
$dir_path = "./proxyserver"
$screen_name = "proxyserver"
# 进入目录
Set-Location -Path $dir_path
# 启动新的 PowerShell Job 并运行 go 程序
Start-Job -Name $screen_name -ScriptBlock { go run main.go }

26
stop_all_server.ps1 Normal file
View File

@ -0,0 +1,26 @@
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
}