Sidneys1

Minecraft Server Startup Batch

Sep 29th, 2014
4,040
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2.  
  3. set config=SSConfig.ini
  4.  
  5. echo Loading settings...
  6.  
  7. :: Here we set up the default values.
  8. set AdditionalArgs=-server -XX:+UseParNewGC -XX:+CMSIncrementalPacing -XX:+AggressiveOpts -XX:ParallelGCThreads=4 -XX:+UseConcMarkSweepGC -XX:ThreadStackSize=256k
  9. set ArchiveDir=backups
  10. set ArchiveName=%DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%.7z
  11. set AutoExit=false
  12. set BackupDefault=N
  13. set BackupTimeout=5
  14. set CleanupDays=10
  15. set CompressionLevel=9
  16. set JarFile=minecraft_server.jar
  17. set MaxRam=1024M
  18. set WorldFolder=world
  19.  
  20. :: And load the config.ini file.
  21. IF EXIST %config% (
  22.     :: For each line in the config file
  23.     for /f "eol=# delims=" %%x in (%config%) do (set "%%x")
  24.     echo Settings loaded!
  25. ) ELSE (
  26.     echo Settings file ^(%config%^) not found! Creating the default one!
  27.     CALL :CREATE_INI
  28.     IF AutoExit==true exit
  29. )
  30.  
  31. CHOICE /C YN /T %BackupTimeout% /D %BackupDefault% /N /M "Backup running in %BackupTimeout% seconds. Press Y to start now or N to cancel..."
  32.  
  33. :: If we chose to run the backup...
  34. IF NOT ERRORLEVEL 2 (
  35.     call 7z.exe a -mx%CompressionLevel% %ArchiveDir%/%ArchiveName% %WorldFolder%/
  36.     forfiles -p %ArchiveDir% -s -m *.* -d -%CleanupDays% -c "cmd /c del @PATH"
  37.     echo Backup run!
  38. ) ELSE (
  39.     echo Backup cancelled... continuing.
  40. )
  41.  
  42. echo.
  43. echo Server starting...
  44.  
  45. echo Checking for JAR file...
  46.  
  47. IF NOT EXIST %JarFile% (
  48.     echo %JarFile% does not exist... Check settings file!
  49.     IF AutoExit==true exit
  50.     GOTO:EOF
  51. )
  52.  
  53. :: Start the server...
  54. echo Launch command will be: javaw -Xmx%MaxRam% %AdditionalArgs% -jar %JarFile%
  55. start "Minecraft Server Launcher" /REALTIME /MIN javaw -Xmx%MaxRam% %AdditionalArgs% -jar %JarFile%
  56.  
  57. IF AutoExit==true exit
  58.  
  59. GOTO:EOF
  60.  
  61. :CREATE_INI
  62.     :: This is the content of the default settings file
  63.     echo # ServerStart.bat settings file.>%config%
  64.  
  65.     echo # Delete and run ServerStart.bat to recreate with defaults.>>%config%
  66.     echo # Deleting a kay=value forces it to default.>>%config%
  67.     echo.>>%config%
  68.     echo # How long to wait, in seconds, before choosing the default backup mode.>>%config%
  69.     echo BackupTimeout=5 >>%config%
  70.     echo.>>%config%
  71.     echo # Default backup option. ^(Y for yes, N for no^)>>%config%
  72.     echo BackupDefault=Y>>%config%
  73.     echo.>>%config%
  74.     echo # Minecraft Jar file. ^(Does not currently support .exe server^)>>%config%
  75.     echo JarFile=minecraft_server.jar>>%config%
  76.     echo.>>%config%
  77.     echo # Maximum RAM to allot the server. Postfix is either K ^(Kilobytes^), M ^(Megabytes^), or G ^(Gigabytes^)>>%config%
  78.     echo MaxRam=1024M>>%config%
  79.     echo.>>%config%
  80.     echo # Any additional Java arguments. Here are some useful defaults...>>%config%
  81.     echo AdditionalArgs=-server -XX:+UseParNewGC -XX:+CMSIncrementalPacing -XX:+AggressiveOpts -XX:ParallelGCThreads=4 -XX:+UseConcMarkSweepGC -XX:ThreadStackSize=256k>>%config%
  82.     echo.>>%config%
  83.     echo # 7-zip compression level ^(for backups^). Values range from 0 ^(no compression^) to 1 through 9 ^(Low through Ultra compression^)>>%config%
  84.     echo CompressionLevel=9 >>%config%
  85.     echo.>>%config%
  86.     echo # 7-zip archive file name. Defaults to YEAR-MONTH-DAY.7z. ^(E.g. 2014-09-29.7z^)>>%config%
  87.     echo ArchiveName=%%DATE:~-4%%-%%DATE:~4,2%%-%%DATE:~7,2%%.7z>>%config%
  88.     echo.>>%config%
  89.     echo # The folder to store backups in. Prefers relative paths.>>%config%
  90.     echo ArchiveDir=backups>>%config%
  91.     echo.>>%config%
  92.     echo # The name of the world save folder.>>%config%
  93.     echo WorldFolder=world>>%config%
  94.     echo.>>%config%
  95.     echo # The number of days to keep backups for. ^(E.g., with a default value of 10, backups older than 10 days are deleted.^)>>%config%
  96.     echo CleanupDays=10 >>%config%
  97.     echo.>>%config%
  98.     echo # Whether or not the script automatically closes the command window after launching the server. (true/false)>>%config%
  99.     echo AutoExit=true>>%config%
  100.  
  101.     echo Settings file written!
  102.     IF AutoExit==true exit
  103. EXIT /B
Advertisement
Add Comment
Please, Sign In to add comment