From 52d37672561c7b55404fcd465e9991d52eea57a5 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 19 Jul 2023 12:12:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E6=8F=90=E4=BA=A4=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=20=E5=85=BC=E5=AE=B9windows=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E7=9A=84=20=20shell?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run_all_server.ps1 | 34 ++++++++++++++++++++++++++++++++++ stop_all_server.ps1 | 26 ++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 run_all_server.ps1 create mode 100644 stop_all_server.ps1 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