Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Variables
- $AtlasDir = "A:"
- $appID = "1006030"
- # Logs Files
- $Date = Get-Date -format "yyyy-MM-dd_HH-mm-ss"
- $SteamCMD_PathFile = "A:\Logs\CRON\Update_SteamCMD_Log.txt"
- $PathFile = "A:\Logs\CRON\$($Date)_Update_Log.txt"
- # Function message
- function logMsg($msg)
- {
- write-Host $msg
- Add-Content $PathFile $msg
- }
- # Force to create a new log file
- $NewFile = New-Item -type file $SteamCMD_PathFile -Force
- # Starting update
- logMsg "$(Get-Date -format "yyyy/MM/dd HH:mm:ss") - Starting validating and updating..."
- #Validating and updating Atlas Server
- powershell.exe "$AtlasDir\SteamCMD\steamcmd.exe" +login anonymous +force_install_dir "$AtlasDir\AtlasServer" +app_update $appID validate +exit > $SteamCMD_PathFile
- # Search the word "updating" to see if Atlas has been updated
- $updating = Select-String -Path $SteamCMD_PathFile -pattern "downloading"
- # Check if the server has been updated
- if ($updating) {
- logMsg "$(Get-Date -format "yyyy/MM/dd HH:mm:ss") - The server has been updated !"
- logMsg "$(Get-Date -format "yyyy/MM/dd HH:mm:ss") - Starting broadcast RCON messages to all servers..."
- # Send a message to all servers that there's an update
- # 10 minutes before the restart
- $Broadcast = "$(Get-Date -format "yyyy/MM/dd HH:mm:ss") - Broadcast message 10 minutes before the restart"
- Add-Content $PathFile $Broadcast
- [string]$updatetext = "The server will restart in 10 minutes for an update."
- powershell -FIle "A:\Launcher\RCON\broadcast_all_servers.ps1" -Text $updatetext
- # sleep 5 minutes
- Sleep -s 300
- # 5 minutes before the restart
- $Broadcast = "$(Get-Date -format "yyyy/MM/dd HH:mm:ss") - Broadcast message 5 minutes before the restart"
- Add-Content $PathFile $Broadcast
- [string]$updatetext = "The server will restart in 5 minutes for an update."
- powershell -FIle "A:\Launcher\RCON\broadcast_all_servers.ps1" -Text $updatetext
- # sleep 4 minutes
- Sleep -s 240
- # 1 minute before the restart
- $Broadcast = "$(Get-Date -format "yyyy/MM/dd HH:mm:ss") - Broadcast message 1 minute before the restart"
- Add-Content $PathFile $Broadcast
- [string]$updatetext = "The server will restart in 1 minute for an update."
- powershell -FIle "A:\Launcher\RCON\broadcast_all_servers.ps1" -Text $updatetext
- # sleep 1 minute
- Sleep -s 60
- # The server will restart now
- $Broadcast = "$(Get-Date -format "yyyy/MM/dd HH:mm:ss") - Broadcast message the server will restart now"
- Add-Content $PathFile $Broadcast
- [string]$updatetext = "The server will restart now for an update."
- powershell -FIle "A:\Launcher\RCON\broadcast_all_servers.ps1" -Text $updatetext
- logMsg "$(Get-Date -format "yyyy/MM/dd HH:mm:ss") - Starting to restart all servers..."
- # Stop all Servers
- powershell -FIle "A:\Launcher\Servers\stop_all_servers.ps1" -Wait
- logMsg "$(Get-Date -format "yyyy/MM/dd HH:mm:ss") - Stopped all servers"
- Sleep -s 5
- # Start all servers
- powershell -FIle "A:\Launcher\Servers\start_all_servers.ps1" -wait
- logMsg "$(Get-Date -format "yyyy/MM/dd HH:mm:ss") - Started all servers"
- logMsg "$(Get-Date -format "yyyy/MM/dd HH:mm:ss") - Update completed with success !"
- } else {
- logMsg "$(Get-Date -format "yyyy/MM/dd HH:mm:ss") - No update detected for the server !"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement