Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ######################################################################
- ## Configuration ##
- ######################################################################
- # Rotate logs, check for Java, execute server continuously #
- # Version 1, written by AssMuncher #
- # #
- # Features: #
- # * Automatically restarts on Crash #
- # * Backs up world before restarting #
- # * Exit loop if configured player is banned #
- # #
- ######################################################################
- # Set these configuration options #
- ######################################################################
- #Uncomment one of these and set your path to the java.exe and override
- # the JAVA_HOME environment variable (if it exists).
- #$Java = "C:\Program Files (x86)\Java\jre6\bin\java.exe"
- #$Java = "C:\Program Files\Java\jre6\bin\java.exe"
- $JavaCLI = "-Xmx1536M -Xms512M"
- #This is the secret "player" you should ban to make the server die. The
- # script will look thru the banned-players.txt file to see if this exists
- # if it does, it will NOT continue to loop.
- #Also, you'll probably have to change this each time if you want it to be
- # secure and have untrusted users. I run a small server for a small group
- # of friends, so this suffices.
- $Secret = "loopserver-shutdown-1111"
- #If you want to use the backup feature, please uncomment this and feed it
- # a path to 7-zip's 7z.exe. Backups will be made in the current directory
- # and named by date/time.
- $Backup = "C:\Program Files\7-Zip\7z.exe"
- ######################################################################
- ## Script Follows ##
- ######################################################################
- function Pause() {
- $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
- }
- if($Env:JAVA_HOME -and !$Java) {
- $Java = "$Env:JAVA_HOME\bin\java.exe"
- }
- elseif(!$Env:JAVA_HOME -and !$Java) {
- Write-Host -foregroundcolor red "Please configure `$Java, your JAVA_HOME is not set or incorrect."
- Pause
- Exit
- }
- do {
- if(!(Test-Path ".\minecraft_server.jar")) {
- Write-Host -foregroundcolor red "Minecraft server JAR not found!"
- Pause
- Exit
- }
- if(!(Test-Path $Java)) {
- Write-Host -foregroundcolor red "Unable to locate suitable JRE!"
- Pause
- Exit
- }
- $cmd = '"' + $Java + '" ' + $JavaCLI + ' -jar minecraft_server.jar nogui'
- cmd /c $cmd
- $ReturnValue = $LastExitCode
- Write-Host -foregroundcolor green "Rotating logs..."
- if(Test-Path ".\server.5.log") { Remove-Item ".\server.5.log" }
- if(Test-Path ".\server.4.log") { Rename-Item ".\server.4.log" ".\server.5.log" }
- if(Test-Path ".\server.3.log") { Rename-Item ".\server.3.log" ".\server.4.log" }
- if(Test-Path ".\server.2.log") { Rename-Item ".\server.2.log" ".\server.3.log" }
- if(Test-Path ".\server.1.log") { Rename-Item ".\server.1.log" ".\server.2.log" }
- if(Test-Path ".\server.log") { Rename-Item ".\server.log" ".\server.1.log" }
- #Backing up scripts
- if($Backup -and (Test-Path $Backup)) {
- Write-Host -foregroundcolor green "Backing up configured world files..."
- $Props = ''
- Get-Content ".\server.properties" | ForEach-Object {$Props = @{}} {
- $Props[$_.split('=')[0]] = $_.split('=')[1]
- }
- $cmd = '"' + $Backup + '" a ' + $Props.'level-name'
- if($ReturnValue -ne 0) {
- $cmd = $cmd + '.crash'
- Write-Host -foregroundcolor yellow "Crash Detected!"
- }
- $cmd = $cmd + '.backup-' + (Get-Date -format MMddyyyy\-HHmmss) + '.7z '
- $cmd = $cmd + $Props.'level-name' + ' -r'
- cmd /c $cmd
- if($LastExitCode -ne 0) {
- Write-Host -foregroundcolor yellow "Backup exited abnormally!"
- }
- }
- }
- while(!(Get-ChildItem .\banned-players.txt | Select-String -SimpleMatch $Secret))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement