diff --git a/run_all_server.ps1 b/run_all_server.ps1 new file mode 100644 index 00000000..d33cec58 --- /dev/null +++ b/run_all_server.ps1 @@ -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 .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 } \ No newline at end of file diff --git a/stop_all_server.ps1 b/stop_all_server.ps1 new file mode 100644 index 00000000..13ca6734 --- /dev/null +++ b/stop_all_server.ps1 @@ -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 +} \ No newline at end of file