-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRconStopOnBackup.ps1
35 lines (33 loc) · 1.16 KB
/
RconStopOnBackup.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
param(
[string]$ServerFileName
)
$serverInstanceCount = @(Get-WmiObject Win32_Process -Filter "name = 'java.exe'" | Where-Object CommandLine -match "$($ServerFileName)").Count
#$serverInstanceCount = 0
if ($serverInstanceCount -ne 0){
rcon "say §aBackup server data, restart in 120 seconds"
rcon "say 备份服务器数据,120秒后重启服务器"
Start-Sleep -Seconds 60
rcon "say §aServer restart in 60 seconds"
rcon "say 60秒后重启服务器"
Start-Sleep -Seconds 30
rcon "say §aServer restart in 30 seconds"
rcon "say 30秒后重启服务器"
Start-Sleep -Seconds 25
rcon "say §aServer restart in 5 seconds"
rcon "say 5秒后重启服务器"
Start-Sleep -Seconds 5
rcon "stop"
}
if ($serverInstanceCount -eq 0){
Write-Output "Server not running, skip rcon commands"
}
while($true){
Start-Sleep -Seconds 1
$serverInstanceCount = @(Get-WmiObject Win32_Process -Filter "name = 'java.exe'" | Where-Object CommandLine -match "$($ServerFileName)").Count
if ($serverInstanceCount -ne 0){
Write-Output "Still waiting for stop..."
}
if ($serverInstanceCount -eq 0){
break
}
}