Advertisement
Guest User

Cron_Update.ps1

a guest
Jan 26th, 2019
663
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Variables
  2. $AtlasDir = "A:"
  3. $appID = "1006030"
  4.  
  5. # Logs Files
  6. $Date = Get-Date -format "yyyy-MM-dd_HH-mm-ss"
  7. $SteamCMD_PathFile = "A:\Logs\CRON\Update_SteamCMD_Log.txt"
  8. $PathFile = "A:\Logs\CRON\$($Date)_Update_Log.txt"
  9.  
  10. # Function message
  11. function logMsg($msg)
  12. {
  13.     write-Host $msg
  14.     Add-Content $PathFile $msg
  15. }
  16.  
  17. # Force to create a new log file
  18. $NewFile = New-Item -type file $SteamCMD_PathFile -Force
  19.  
  20. # Starting update
  21. logMsg "$(Get-Date -format "yyyy/MM/dd HH:mm:ss") - Starting validating and updating..."
  22.  
  23. #Validating and updating Atlas Server
  24. powershell.exe "$AtlasDir\SteamCMD\steamcmd.exe" +login anonymous +force_install_dir "$AtlasDir\AtlasServer" +app_update $appID validate +exit > $SteamCMD_PathFile
  25.  
  26. # Search the word "updating" to see if Atlas has been updated
  27. $updating = Select-String -Path $SteamCMD_PathFile -pattern "downloading"
  28.  
  29.  
  30. # Check if the server has been updated
  31. if ($updating)  {
  32.     logMsg "$(Get-Date -format "yyyy/MM/dd HH:mm:ss") - The server has been updated !"
  33.     logMsg "$(Get-Date -format "yyyy/MM/dd HH:mm:ss") - Starting broadcast RCON messages to all servers..."
  34.  
  35.     # Send a message to all servers that there's an update
  36.  
  37.     # 10 minutes before the restart
  38.     $Broadcast = "$(Get-Date -format "yyyy/MM/dd HH:mm:ss") - Broadcast message 10 minutes before the restart"
  39.     Add-Content $PathFile $Broadcast
  40.    
  41.     [string]$updatetext = "The server will restart in 10 minutes for an update."
  42.     powershell -FIle "A:\Launcher\RCON\broadcast_all_servers.ps1" -Text $updatetext
  43.  
  44.     # sleep 5 minutes
  45.     Sleep -s 300
  46.  
  47.     # 5 minutes before the restart
  48.     $Broadcast = "$(Get-Date -format "yyyy/MM/dd HH:mm:ss") - Broadcast message 5 minutes before the restart"
  49.     Add-Content $PathFile $Broadcast
  50.  
  51.     [string]$updatetext = "The server will restart in 5 minutes for an update."
  52.     powershell -FIle "A:\Launcher\RCON\broadcast_all_servers.ps1" -Text $updatetext
  53.  
  54.     # sleep 4 minutes
  55.     Sleep -s 240
  56.  
  57.     # 1 minute before the restart
  58.     $Broadcast = "$(Get-Date -format "yyyy/MM/dd HH:mm:ss") - Broadcast message 1 minute before the restart"
  59.     Add-Content $PathFile $Broadcast
  60.  
  61.     [string]$updatetext = "The server will restart in 1 minute for an update."
  62.     powershell -FIle "A:\Launcher\RCON\broadcast_all_servers.ps1" -Text $updatetext
  63.  
  64.     # sleep 1 minute
  65.     Sleep -s 60
  66.  
  67.     # The server will restart now
  68.     $Broadcast = "$(Get-Date -format "yyyy/MM/dd HH:mm:ss") - Broadcast message the server will restart now"
  69.     Add-Content $PathFile $Broadcast
  70.  
  71.     [string]$updatetext = "The server will restart now for an update."
  72.     powershell -FIle "A:\Launcher\RCON\broadcast_all_servers.ps1" -Text $updatetext
  73.  
  74.  
  75.     logMsg "$(Get-Date -format "yyyy/MM/dd HH:mm:ss") - Starting to restart all servers..."
  76.  
  77.     # Stop all Servers
  78.     powershell -FIle "A:\Launcher\Servers\stop_all_servers.ps1" -Wait
  79.  
  80.     logMsg "$(Get-Date -format "yyyy/MM/dd HH:mm:ss") - Stopped all servers"
  81.  
  82.     Sleep -s 5
  83.  
  84.     # Start all servers
  85.     powershell -FIle "A:\Launcher\Servers\start_all_servers.ps1" -wait
  86.  
  87.     logMsg "$(Get-Date -format "yyyy/MM/dd HH:mm:ss") - Started all servers"
  88.     logMsg "$(Get-Date -format "yyyy/MM/dd HH:mm:ss") - Update completed with success !"
  89.    
  90. } else {
  91.     logMsg "$(Get-Date -format "yyyy/MM/dd HH:mm:ss") - No update detected for the server !"
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement