├── .gitattributes ├── LICENSE.md ├── README.md ├── ServerStart.bat ├── ServerStart.sh └── settings.cfg /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | *.txt text eol=crlf 4 | *.bat text eol=crlf 5 | *.cfg text eol=crlf 6 | *.sh text eol=lf 7 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | 2 | # Custom License 3 | The *only* reason we included a license is because we wanted it to be **easier** for more people to use/share this. Some places (i.e. Curse) need some form of "official" notice allowing content to be used. Since we were making a license anyway, we thought it would be nice to add an attribution clause so others didn't try to claim our work as their own. The result is this custom license based on a combination of the [MIT license](https://opensource.org/licenses/MIT) and a couple parts from Vaskii's [Botania](http://botaniamod.net/license.php)/[Psi](http://psi.vazkii.us/license.php) license: 4 | ``` 5 | Copyright (c) 2017 All The Mods Team 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | You must give appropriate credit to the "All The Mods Team" as original 15 | creators for any parts of this Software being used. A link back to original 16 | content is optional but would be greatly appreciated. 17 | 18 | It is forbidden to charge for access to the distribution of this Software or 19 | gain money through it. This includes any type of inline advertisement, such 20 | as url shorteners (adf.ly or otherwise) or ads. This also includes 21 | restricting any amount of access behind a paywall. Special permission is 22 | given to allow this Software to be bundled or distributed with projects on 23 | Curse.com, CurseForge.com or their related sub-domains and subsidiaries. 24 | 25 | Derivative works must be open source (have its source visible and allow for 26 | redistribution and modification). 27 | 28 | The above copyright notice and conditions must be included in all copies or 29 | substantial portions of the Software, including derivative works and 30 | re-licensing thereof. 31 | ``` 32 | 33 | ____________________________ 34 | ## DISCLAIMERS 35 | 36 | "All The Mods Team" is not affiliated with "Mojang," "Oracle," "Curse," "Twitch," "Sponge," "Forge" or any other entity (or entity owning a referenced product) potentially mentioned in this document or relevant source code for this Software. The use of their names and/or trademarks is strictly circumstantial and assumed fair-use. All credit for their respective works, software, branding, copyrights and/or trademarks belongs entirely to them as original owners/licensers. 37 | 38 | ``` 39 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 40 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 41 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 42 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 43 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 44 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 45 | SOFTWARE. 46 | ``` 47 | 48 | 49 | _______________________________ 50 | 51 | 52 |
53 |
54 |
55 |
56 |

57 | All The Mods 58 |

59 |
60 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Modpack ServerStart Scripts 2 | 3 | Minecraft-Forge Server install/launcher script 4 | 5 | Created and supported by the All The Mods Team with special thanks to @OrdinatorStouff and @Dijkstra 6 | 7 | GitHub: https://github.com/AllTheMods/Server-Scripts 8 | AllTheMods Discord: https://discord.gg/FdFDVWb 9 | 10 | Originally created for use in "All The Mods" modpacks, but is **free for anyone to use, modify or distribute** provided the conditions of the custom license (detailed below) are met. 11 | 12 |
13 | 14 |
15 | 16 |
17 | 18 | 19 | ## Description 20 | #### OS Batch/Script to help install/run modpack servers. Available for Windows and Linux (Bash). 21 | 22 | These scripts will fetch the appropriate Forge installer and install it. This will also install Mojang's distribution-restricted Minecraft binary and the required libraries. 23 | 24 | After Forge/Minecraft are installed, the same script will act as a launcher to start the server, with an auto-restart-after-crash feature as well. (No need for a separate "install" script). It's also adaptable to smoothly transition to new versions of Forge *even on existing servers that have already been setup*. If the installed Forge version is different from what's supplied in the settings.cfg, the script will remove the old Forge and re-download and install the version specified. The script also performs *many* basic checks such as looking for a valid Java version installed and checking that EULA.txt has been updated. 25 | 26 | All relevant settings are in the easily accessible "settings.cfg" file; Modpack creators can specify their pack's Minecraft and Forge versions, and server operators can specify JVM args and RAM allocation as desired. 27 | 28 | IF THERE ARE ANY ISSUES 29 | Please make a report on the github linked above 30 | 31 | 32 |
33 | 34 |
35 | 36 |
37 | 38 | 39 | # How To Use 40 | 41 | #### Do not modify `ServerStart.bat` or `ServerStart.sh` 42 | #### All settings are modified in `settings.cfg` instead. 43 | 44 | Windows: **`ServerStart.Bat`** *(Run/Double-Click)* 45 | Linux: **`bash ServerStart.sh`** *(must be bash, not shell/sh)* 46 | 47 | #### Arguments 48 | | Setting | Description | 49 | | ----------|----------------------------| 50 | | -i, --install, install | Runs only the install portion of the script. The server will not automatically start after.| 51 | | -a, --auto | Skips user input stages and uses default values instead | 52 | 53 | #### If you're running your server on a remote system, the following command can be used to keep it running even when you close your terminal: 54 | ``` 55 | nohup ./ServerStart.sh -a &>/dev/null & 56 | ``` 57 | ________________ 58 | 59 | ### settings.cfg 60 | Formatting is very important for it to load correctly: 61 | * `SETTING=VALUE` 62 | * No spaces around the equal sign 63 | * One setting per line 64 | 65 | 66 | | Setting | Description | Example Value | 67 | | ----------|----------------------------| :------------:| 68 | | **MAX_RAM** | How much max RAM to allow the JVM to allocate to the server | `5G` | 69 | | **JAVA_ARGS** | The defaults provided should be best for most people, but can be edited if desired | *See Below* | 70 | | **CRASH_COUNT** | The max number of consecutive crashes that each occur within so many seconds of each other. If max is reaches, the script will exit. This is to stop spamming restarts of a server with a critical issue. | `8` | 71 | | **CRASH_TIMER** | The number of seconds to consider a crash within to be "consecutive" | `600` | 72 | | **RUN_FROM_BAD_FOLDER** | The scripts will not run from "temp" folders or "system" folders. If you want to force allow this, change the value to `1` | `0` | 73 | | **IGNORE_OFFLINE** | The scripts will not run if a connection to the internet can not be found. If you want to force allow (i.e. to run a server for local/LAN only) then set to `1`. Note, however that it will need internet connection to at least perform initial download/install of the Forge binaries | `0` | 74 | | **IGNORE_JAVA_CHECK** | By default, the script will stop/error if it can not find 64-bit Java 1.8 or 1.9. Some packs might be able to run with less than 4G or RAM or on older 1.7 java. If you want to use an older version or are limited to a 32-bit OS, setting this to `1` will let the script continue | `0` | 75 | | **USE_SPONGE** | Mostly unsupported and experimental. If set to `1` script will attempt to launch SpongeBootstrap but only if the bootstrap is present and SpongeForge is in Mods folder. This will not download/setup the required files either, merely launch the pack using them. **Sponge can cause undocumented errors and conflicts and therefore it's use is rarely supported by modpack developers. USE AT YOUR OWN RISK and only if you know what you're doing** | `0` | 76 | | **HIGH_CPU_PRIORITY** | This will attempt to start the Java process in a higher priority than "normal." This shouldn't have a major negative impact on the host computer but if it's causing conflicts or taking too much CPU time you can try disabling. *Linux implementation is still WIP (TODO)* | `1` | 77 | | **MODPACK_NAME** | Pack name to add flavor/description to script as it's running. Quotes are not needed. Can contain spaces. Technically can be very long, but will work better if short/concise (i.e. "Illumination" would be *much* better to use than "All The Mods Presents: Illumination") | `All The Mods` | 78 | | **DEFAULT_WORLD_TYPE** | Allows for changing the type of world used. | `BIOMESOP` | 79 | | **MCVER** | Target Minecraft version. Usually set by pack dev before distributing and not intended to be changed by end-users. Must be complete/exact and matching the version on Forge's website (i.e. `1.10` is not the same as `1.10.2`) | `1.10.2` | 80 | | **FORGEVER** | Target Forge version. Usually set by pack dev before distributing and not intended to be changed by end-users. Requires the full version and exactly matching Forge's website. (i.e. `2254` will not work, but `12.18.3.2254` will) | `12.18.3.2281` | 81 | | **FORGEURL** | Direct url to a Forge "installer" jar. Mostly for debugging purposes, but if a URL is specified, the Forge installer of this link will be downloaded regardless of the previous settings.\* | `DISABLE` | 82 | 83 | 84 | \**NOTE: Another debug/bypass options is for modpack creators to package and redistribute the forge installer matching their desired version as long as it's name matches the format: `forge---installer.jar` If included, none will need to be downloaded first.* 85 | 86 |
87 | 88 |
89 | 90 |
91 | 92 | 93 | ## Optional Java Arguments 94 | 95 | Java can be tweaked with launch settings that can sometimes improve the performance of Minecraft over default (no launch options), especially for 1.10+ and larger packs such as All The Mods. 96 | 97 |
98 | 99 | 100 | ______________________________ 101 | **BASIC** 102 | These basic settings are recommended for general use for any modpack: 103 | ``` 104 | -d64 -server -XX:+AggressiveOpts -XX:ParallelGCThreads=3 -XX:+UseConcMarkSweepGC -XX:+UnlockExperimentalVMOptions -XX:+UseParNewGC -XX:+ExplicitGCInvokesConcurrent -XX:MaxGCPauseMillis=10 -XX:GCPauseIntervalMillis=50 -XX:+UseFastAccessorMethods -XX:+OptimizeStringConcat -XX:NewSize=84m -XX:+UseAdaptiveGCBoundary -XX:NewRatio=3 -Dfml.readTimeout=90 -Ddeployment.trace=true -Ddeployment.log=true -Ddeployment.trace.level=all -Dfml.debugNetworkHandshake=true -Dfml.badPacketCounter=10 105 | ``` 106 | 107 | 108 |
109 | 110 | ______________________________ 111 | There are many opinions on what's considered good or not-so-good to use for JVM args that change from person-to-person, and over time. The settings above were based on [this great discussion/explanation](https://www.reddit.com/r/feedthebeast/comments/5jhuk9/modded_mc_and_memory_usage_a_history_with_a/) by CPW, the lead dev of EnderIO and a prominent contributor to the Forge project. 112 | 113 | 114 | 115 |
116 | 117 |
118 | 119 |
120 | 121 | 122 | # Background Story 123 | Mojang's [Minecraft EULA](https://account.mojang.com/documents/minecraft_eula) is extremely open and forgiving, going so far as to "encourage you to do cool stuff." One of the very few explicit restrictions and "the one major rule" prohibits re-distributing Minecraft or any part of it (including the Minecraft server binary files): 124 | > "In order to ensure the integrity of the Game, we need all Game downloads and updates to come from an authorized source. It's also important for us that 3rd party tools/services don't seem "official" as we can't guarantee their quality. It's part of the responsibility we have to the customers of Minecraft." 125 | 126 | This means that any modpack team/developer that wants to provide users with a *ready-to-use* server file package can't provide all the binaries and therefore would be incomplete. This script bridges that gap by dynamically fetching and installing MinecraftForge. The forge installer conveniently fetches the Minecraft binaries from Mojang's servers as well as the required library files as well providing a seamless "install" step followed by launching/running the server after initial setup. 127 | 128 | From there we decided we wanted to go all-out providing as many features and configuration options as possible to make setting up and running a server as easy as possible. We want this to be more than just a simple "workaround" to the distribution restriction, but a full-featured option for server operators that don't use a control panel or management software. 129 | 130 | 131 | 132 | 133 | 134 | 135 | _____________________ 136 | 137 |
138 | 139 |
140 | 141 |
142 | 143 | 144 | # Custom License 145 | The *only* reason we included a license is because we wanted it to be **easier** for more people to use/share this. Some places (i.e. Curse) need some form of "official" notice allowing content to be used. Since we were making a license anyway, we thought it would be nice to add an attribution clause so others didn't try to claim our work as their own. The result is this custom license based on a combination of the [MIT license](https://opensource.org/licenses/MIT) and a couple parts from Vaskii's [Botania](http://botaniamod.net/license.php)/[Psi](http://psi.vazkii.us/license.php) license: 146 | ``` 147 | Copyright (c) 2017 All The Mods Team 148 | 149 | Permission is hereby granted, free of charge, to any person obtaining a copy 150 | of this software and associated documentation files (the "Software"), to deal 151 | in the Software without restriction, including without limitation the rights 152 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 153 | copies of the Software, and to permit persons to whom the Software is 154 | furnished to do so, subject to the following conditions: 155 | 156 | You must give appropriate credit to the "All The Mods Team" as original 157 | creators for any parts of this Software being used. A link back to original 158 | content is optional but would be greatly appreciated. 159 | 160 | It is forbidden to charge for access to the distribution of this Software or 161 | gain money through it. This includes any type of inline advertisement, such 162 | as url shorteners (adf.ly or otherwise) or ads. This also includes 163 | restricting any amount of access behind a paywall. Special permission is 164 | given to allow this Software to be bundled or distributed with projects on 165 | Curse.com, CurseForge.com or their related sub-domains and subsidiaries. 166 | 167 | Derivative works must be open source (have its source visible and allow for 168 | redistribution and modification). 169 | 170 | The above copyright notice and conditions must be included in all copies or 171 | substantial portions of the Software, including derivative works and 172 | re-licensing thereof. 173 | ``` 174 | 175 | ____________________________ 176 | ## DISCLAIMERS 177 | 178 | "All The Mods Team" is not affiliated with "Mojang," "Oracle," "Curse," "Twitch," "Sponge," "Forge" or any other entity (or entity owning a referenced product) potentially mentioned in this document or relevant source code for this Software. The use of their names and/or trademarks is strictly circumstantial and assumed fair-use. All credit for their respective works, software, branding, copyrights and/or trademarks belongs entirely to them as original owners/licensers. 179 | 180 | ``` 181 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 182 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 183 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 184 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 185 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 186 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 187 | SOFTWARE. 188 | ``` 189 | 190 | 191 | _______________________________ 192 | 193 | 194 |
195 |
196 |
197 |
198 |

199 | All The Mods 200 |

201 |
202 | 203 | -------------------------------------------------------------------------------- /ServerStart.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | :::: 3 | :::: Minecraft-Forge Server install/launcher script 4 | :::: Created by the "All The Mods" pack team 5 | :::: 6 | :::: This script will setup and start the minecraft server 7 | :::: *** THIS FILE NOT INTENDED TO BE EDITED, USE "settings.cfg" INSTEAD *** 8 | :::: 9 | :::: FOR HELP (or more details); 10 | :::: Github: https://github.com/AllTheMods/Server-Scripts 11 | :::: Discord: https://discord.gg/FdFDVWb 12 | :::: 13 | 14 | :::: *** THIS FILE NOT INTENDED TO BE EDITED, USE "settings.cfg" INSTEAD *** 15 | 16 | ::================================================================================:: 17 | ::*** LICENSE ***:: 18 | 19 | :: The only reason we included a license is because we wanted it to be easier 20 | :: for more people to use/share this. Some places (i.e. Curse) need some form of 21 | :: "official" notice allowing content to be used. Since we were making a license 22 | :: anyway, we thought it would be nice to add an attribution clause so others 23 | :: didn't try to claim our work as their own. The result is this custom license 24 | :: based on a combination of the MIT license and a couple parts from Vaskii's 25 | :: Botania/Psi license: 26 | 27 | :: Copyright (c) 2017 All The Mods Team 28 | 29 | :: Permission is hereby granted, free of charge, to any person obtaining a copy 30 | :: of this software and associated documentation files (the "Software"), to deal 31 | :: in the Software without restriction, including without limitation the rights 32 | :: to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 33 | :: copies of the Software, and to permit persons to whom the Software is 34 | :: furnished to do so, subject to the following conditions: 35 | 36 | :: You must give appropriate credit to the "All The Mods Team" as original 37 | :: creators for any parts of this Software being used. A link back to original 38 | :: content is optional but would be greatly appreciated. 39 | 40 | :: It is forbidden to charge for access to the distribution of this Software or 41 | :: gain money through it. This includes any type of inline advertisement, such 42 | :: as url shorteners (adf.ly or otherwise) or ads. This also includes 43 | :: restricting any amount of access behind a paywall. Special permission is 44 | :: given to allow this Software to be bundled or distributed with projects on 45 | :: Curse.com, CurseForge.com or their related sub-domains and subsidiaries. 46 | 47 | :: Derivative works must be open source (have its source visible and allow for 48 | :: redistribution and modification). 49 | 50 | :: The above copyright notice and conditions must be included in all copies or 51 | :: substantial portions of the Software, including derivative works and 52 | :: re-licensing thereof. 53 | 54 | ::================================================================================:: 55 | ::*** DISCLAIMERS ***:: 56 | 57 | :: "All The Mods Team" is not affiliated with "Mojang," "Oracle," 58 | :: "Curse," "Twitch," "Sponge," "Forge" or any other entity (or entity owning a 59 | :: referenced product) potentially mentioned in this document or relevant source 60 | :: code for this Software. The use of their names and/or trademarks is strictly 61 | :: circumstantial and assumed fair-use. All credit for their respective works, 62 | :: software, branding, copyrights and/or trademarks belongs entirely to them as 63 | :: original owners/licensers. 64 | 65 | :: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 66 | :: IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 67 | :: FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 68 | :: AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 69 | :: LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 70 | :: OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 71 | :: SOFTWARE. 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | :::: *** THIS FILE NOT INTENDED TO BE EDITED, USE "settings.cfg" INSTEAD *** 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | SETLOCAL 90 | REM Internal Scripty stuff 91 | REM Define system root so we can run CORRECT version of things (like FIND) 92 | SET MC_SYS32=%SYSTEMROOT%\SYSTEM32 93 | REM default an error code in case error block is ran without this var being defined first 94 | SET MC_SERVER_ERROR_REASON=Unspecified 95 | REM this is a temp variable to use for intermidiate calculations and such 96 | SET MC_SERVER_TMP_FLAG=0 97 | REM this is the var to keep track of sequential crashes 98 | SET MC_SERVER_CRASH_COUNTER=1 99 | REM set "crash time" to initial script start 100 | SET MC_SERVER_CRASH_YYYYMMDD=%date:~10,4%%date:~4,2%%date:~7,2% 101 | SET MC_SERVER_CRASH_HHMMSS=%time:~0,2%%time:~3,2%%time:~6,2% 102 | 103 | REM Create log FOLDER if it doesn't exist 104 | IF NOT EXIST "%~dp0logs\" (MKDIR logs && echo created non-existent "logs" folder) 105 | 106 | REM delete log if already exists to start a fresh one 107 | IF EXIST "%~dp0logs\serverstart.log" DEL /F /Q "%~dp0logs\serverstart.log" 108 | ECHO. 1>> "%~dp0logs\serverstart.log" 2>&1 109 | ECHO. 1>> "%~dp0logs\serverstart.log" 2>&1 110 | ECHO. 1>> "%~dp0logs\serverstart.log" 2>&1 111 | ECHO ----------------------------------------------------------------- 1>> "%~dp0logs\serverstart.log" 2>&1 112 | ECHO INFO: Starting batch at %MC_SERVER_CRASH_YYYYMMDD%:%MC_SERVER_CRASH_HHMMSS% 1>> "%~dp0logs\serverstart.log" 2>&1 113 | ECHO ----------------------------------------------------------------- 1>> "%~dp0logs\serverstart.log" 2>&1 114 | ECHO. 1>> "%~dp0logs\serverstart.log" 2>&1 115 | ECHO DEBUG: Current Dir is %CD% -- trying to change to %~dp0 1>> "%~dp0logs\serverstart.log" 2>&1 116 | CD "%~dp0" 1>> "%~dp0logs\serverstart.log" 2>&1 117 | 118 | :BEGIN 119 | CLS 120 | COLOR 3F 121 | 122 | REM Check for config file 123 | ECHO INFO: Checking that settings.cfg exists 1>> "%~dp0logs\serverstart.log" 2>&1 124 | IF NOT EXIST "%~dp0settings.cfg" ( 125 | SET MC_SERVER_ERROR_REASON=Settings.cfg_Not_Found 126 | GOTO ERROR 127 | ) 128 | 129 | ECHO DEBUG: settings.cfg Found. Logging full contents below: 1>> "%~dp0logs\serverstart.log" 2>&1 130 | >nul COPY "%~dp0logs\serverstart.log"+"%~dp0settings.cfg" "%~dp0logs\serverstart.log" 131 | ECHO. 1>> "%~dp0logs\serverstart.log" 2>&1 132 | 133 | >nul %MC_SYS32%\FIND.EXE /I "MAX_RAM=" "%~dp0settings.cfg" || ( 134 | SET MC_SERVER_ERROR_REASON=Settings.cfg_Error:MAX_RAM 135 | GOTO ERROR 136 | ) 137 | 138 | >nul %MC_SYS32%\FIND.EXE /I "JAVA_ARGS=" "%~dp0settings.cfg" || ( 139 | SET MC_SERVER_ERROR_REASON=Settings.cfg_Error:JAVA_ARGS 140 | GOTO ERROR 141 | ) 142 | 143 | >nul %MC_SYS32%\FIND.EXE /I "CRASH_COUNT=" "%~dp0settings.cfg" || ( 144 | SET MC_SERVER_ERROR_REASON=Settings.cfg_Error:CRASH_COUNT 145 | GOTO ERROR 146 | ) 147 | 148 | >nul %MC_SYS32%\FIND.EXE /I "CRASH_TIMER=" "%~dp0settings.cfg" || ( 149 | SET MC_SERVER_ERROR_REASON=Settings.cfg_Error:CRASH_TIMER 150 | GOTO ERROR 151 | ) 152 | 153 | >nul %MC_SYS32%\FIND.EXE /I "RUN_FROM_BAD_FOLDER=" "%~dp0settings.cfg" || ( 154 | SET MC_SERVER_ERROR_REASON=Settings.cfg_Error:RUN_FROM_BAD_FOLDER 155 | GOTO ERROR 156 | ) 157 | 158 | >nul %MC_SYS32%\FIND.EXE /I "IGNORE_OFFLINE=" "%~dp0settings.cfg" || ( 159 | SET MC_SERVER_ERROR_REASON=Settings.cfg_Error:IGNORE_OFFLINE 160 | GOTO ERROR 161 | ) 162 | 163 | >nul %MC_SYS32%\FIND.EXE /I "IGNORE_JAVA_CHECK=" "%~dp0settings.cfg" || ( 164 | SET MC_SERVER_ERROR_REASON=Settings.cfg_Error:IGNORE_JAVA_CHECK 165 | GOTO ERROR 166 | ) 167 | 168 | >nul %MC_SYS32%\FIND.EXE /I "MCVER=" "%~dp0settings.cfg" || ( 169 | SET MC_SERVER_ERROR_REASON=Settings.cfg_Error:MCVER 170 | GOTO ERROR 171 | ) 172 | 173 | >nul %MC_SYS32%\FIND.EXE /I "FORGEVER=" "%~dp0settings.cfg" || ( 174 | SET MC_SERVER_ERROR_REASON=Settings.cfg_Error:FORGEVER 175 | GOTO ERROR 176 | ) 177 | 178 | >nul %MC_SYS32%\FIND.EXE /I "FORGEURL=" "%~dp0settings.cfg" || ( 179 | SET MC_SERVER_ERROR_REASON=Settings.cfg_Error:FORGEURL 180 | GOTO ERROR 181 | ) 182 | 183 | >nul %MC_SYS32%\FIND.EXE /I "DEFAULT_WORLD_TYPE=" "%~dp0settings.cfg" || ( 184 | SET MC_SERVER_ERROR_REASON=Settings.cfg_Error:DEFAULT_WORLD_TYPE 185 | GOTO ERROR 186 | ) 187 | 188 | REM LOAD Settings from config 189 | ECHO INFO: Loading variables from settings.cfg 1>> "%~dp0logs\serverstart.log" 2>&1 190 | for /F "delims=; tokens=1 eol=;" %%A in (settings.cfg) DO ( 191 | REM Only process the line if it contains an "equals" sign 192 | ECHO.%%A | findstr /C:"=">nul && ( 193 | CALL SET %%A 194 | ) || ( 195 | REM Skipping Line without equals (blank or comments only) 196 | ) 197 | ) 198 | REM Old way to parse settings--> broke if args had an "equals" (=) character 199 | REM for /f "delims==; tokens=1,2 eol=;" %%G in (settings.cfg) do set %%G=%%H 200 | 201 | REM Define Xms (min heap) as Floor(MAX_RAM / 2) 202 | SET MC_SERVER_TMP_FLAG= 203 | SET /A "MC_SERVER_TMP_FLAG=%MAX_RAM:~0,-1%/2" 204 | FOR /f "tokens=1 delims=." %%a in ("%MC_SERVER_TMP_FLAG%") DO (SET MC_SERVER_TMP_FLAG=%%a) 205 | IF %MC_SERVER_TMP_FLAG% LSS 1 (SET MC_SERVER_TMP_FLAG=1) 206 | 207 | REM Set some placeholder defaults (failsafe if settings.cfg is old version or corrupt somehow 208 | SET MC_SERVER_MAX_RAM=5G 209 | SET MC_SERVER_JVM_ARGS=-Xmx%MC_SERVER_MAX_RAM% 210 | SET MC_SERVER_MAX_CRASH=5 211 | SET MC_SERVER_CRASH_TIMER=600 212 | SET MC_SERVER_RUN_FROM_BAD_FOLDER=0 213 | SET MC_SERVER_IGNORE_OFFLINE=0 214 | SET MC_SERVER_IGNORE_JAVA=0 215 | SET MC_SERVER_MCVER=1.12.2 216 | SET MC_SERVER_FORGEVER=14.23.2.2625 217 | SET MC_SERVER_FORGEURL=DISABLE 218 | SET MC_SERVER_SPONGE=0 219 | SET MC_SERVER_HIGH_PRIORITY=0 220 | SET MC_SERVER_PACKNAME=PLACEHOLDER 221 | SET MC_SERVER_WORLDTYPE=BIOMESOP 222 | 223 | REM Re-map imported vars (from settings.cfg) into script-standard variables 224 | SET MC_SERVER_MAX_RAM=%MAX_RAM% 225 | SET MC_SERVER_JVM_ARGS=-Xmx%MC_SERVER_MAX_RAM% -Xms%MC_SERVER_TMP_FLAG%%MC_SERVER_MAX_RAM:~-1% %JAVA_ARGS% 226 | SET MC_SERVER_MAX_CRASH=%CRASH_COUNT% 227 | SET MC_SERVER_CRASH_TIMER=%CRASH_TIMER% 228 | SET MC_SERVER_RUN_FROM_BAD_FOLDER=%RUN_FROM_BAD_FOLDER% 229 | SET MC_SERVER_IGNORE_OFFLINE=%IGNORE_OFFLINE% 230 | SET MC_SERVER_IGNORE_JAVA=%IGNORE_JAVA_CHECK% 231 | SET MC_SERVER_MCVER=%MCVER% 232 | SET MC_SERVER_FORGEVER=%FORGEVER% 233 | SET MC_SERVER_FORGEURL=%FORGEURL% 234 | SET MC_SERVER_SPONGE=%USE_SPONGE% 235 | SET MC_SERVER_HIGH_PRIORITY=%HIGH_CPU_PRIORITY% 236 | SET MC_SERVER_PACKNAME=%MODPACK_NAME% 237 | SET MC_SERVER_WORLDTYPE=%DEFAULT_WORLD_TYPE% 238 | 239 | REM Cleanup imported vars after being remapped 240 | SET MAX_RAM= 241 | SET FORGE_JAR= 242 | SET JAVA_ARGS= 243 | SET CRASH_COUNT= 244 | SET CRASH_TIMER= 245 | SET RUN_FROM_BAD_FOLDER= 246 | SET IGNORE_OFFLINE= 247 | SET MCVER= 248 | SET FORGEVER= 249 | SET FORGEURL= 250 | SET USE_SPONGE= 251 | SET HIGH_CPU_PRIORITY= 252 | SET MODPACK_NAME= 253 | SET MC_SERVER_TMP_FLAG= 254 | 255 | REM Get forge shorthand version number 256 | SET MC_SERVER_FORGESHORT=%MC_SERVER_FORGEVER:~-4% 257 | 258 | TITLE %MC_SERVER_PACKNAME% ServerStart Script 259 | ECHO. 260 | ECHO *** Loading %MC_SERVER_PACKNAME% Server *** 261 | ECHO Running Forge %MC_SERVER_FORGESHORT% for Minecraft %MC_SERVER_MCVER% 262 | TIMEOUT 1 >nul 263 | ECHO. 264 | ECHO :::::::::::::::::::::::::::::::::::::::::::::::::::: 265 | ECHO Minecraft-Forge Server install/launcher script 266 | ECHO (Created by the "All The Mods" modpack team) 267 | ECHO :::::::::::::::::::::::::::::::::::::::::::::::::::: 268 | ECHO. 269 | ECHO This script will launch a Minecraft Forge Modded server 270 | ECHO. 271 | ECHO FOR HELP (or more details); 272 | ECHO Github: https://github.com/AllTheMods/Server-Scripts 273 | ECHO Discord: https://discord.gg/FdFDVWb 274 | ECHO. 275 | ECHO. 276 | 277 | ECHO DEBUG: Starting variable definitions: 1>> "%~dp0logs\serverstart.log" 2>&1 278 | ECHO DEBUG: MC_SERVER_MAX_RAM=%MC_SERVER_MAX_RAM% 1>> "%~dp0logs\serverstart.log" 2>&1 279 | ECHO DEBUG: MC_SERVER_FORGE_JAR=%MC_SERVER_FORGE_JAR% 1>> "%~dp0logs\serverstart.log" 2>&1 280 | ECHO DEBUG: MC_SERVER_SPONGE_BOOT=%MC_SERVER_SPONGE_BOOT% 1>> "%~dp0logs\serverstart.log" 2>&1 281 | ECHO DEBUG: MC_SERVER_JVM_ARGS=%MC_SERVER_JVM_ARGS% 1>> "%~dp0logs\serverstart.log" 2>&1 282 | ECHO DEBUG: MC_SERVER_MAX_CRASH=%MC_SERVER_MAX_CRASH% 1>> "%~dp0logs\serverstart.log" 2>&1 283 | ECHO DEBUG: MC_SERVER_CRASH_TIMER=%MC_SERVER_CRASH_TIMER% 1>> "%~dp0logs\serverstart.log" 2>&1 284 | ECHO DEBUG: MC_SERVER_IGNORE_OFFLINE=%MC_SERVER_IGNORE_OFFLINE% 1>> "%~dp0logs\serverstart.log" 2>&1 285 | ECHO DEBUG: MC_SERVER_RUN_FROM_BAD_FOLDER=%MC_SERVER_RUN_FROM_BAD_FOLDER% 1>> "%~dp0logs\serverstart.log" 2>&1 286 | ECHO DEBUG: MC_SERVER_MCVER=%MC_SERVER_MCVER% 1>> "%~dp0logs\serverstart.log" 2>&1 287 | ECHO DEBUG: MC_SERVER_FORGEVER=%MC_SERVER_FORGEVER% 1>> "%~dp0logs\serverstart.log" 2>&1 288 | ECHO DEBUG: MC_SERVER_FORGESHORT=%MC_SERVER_FORGESHORT% 1>> "%~dp0logs\serverstart.log" 2>&1 289 | ECHO DEBUG: MC_SERVER_FORGEURL=%MC_SERVER_FORGEURL% 1>> "%~dp0logs\serverstart.log" 2>&1 290 | ECHO DEBUG: MC_SERVER_SPONGE=%MC_SERVER_SPONGE% 1>> "%~dp0logs\serverstart.log" 2>&1 291 | ECHO DEBUG: MC_SERVER_HIGH_PRIORITY=%MC_SERVER_HIGH_PRIORITY% 1>> "%~dp0logs\serverstart.log" 2>&1 292 | ECHO DEBUG: MC_SERVER_PACKNAME=%MC_SERVER_PACKNAME% 1>> "%~dp0logs\serverstart.log" 2>&1 293 | ECHO DEBUG: MC_SERVER_WORLDTYPE=%MC_SERVER_WORLDTYPE% 1>> "%~dp0logs\serverstart.log" 2>&1 294 | ECHO DEBUG: MC_SERVER_SPONGEURL=%MC_SERVER_SPONGEURL% 1>> "%~dp0logs\serverstart.log" 2>&1 295 | REM ECHO DEBUG: MC_SERVER_SPONGEBOOTSTRAPURL=%MC_SERVER_SPONGEBOOTSTRAPURL% 1>> "%~dp0logs\serverstart.log" 2>&1 296 | ECHO DEBUG: MC_SERVER_ERROR_REASON=%MC_SERVER_ERROR_REASON% 1>> "%~dp0logs\serverstart.log" 2>&1 297 | ECHO DEBUG: MC_SERVER_TMP_FLAG=%MC_SERVER_TMP_FLAG% 1>> "%~dp0logs\serverstart.log" 2>&1 298 | ECHO DEBUG: MC_SERVER_CRASH_COUNTER=%MC_SERVER_CRASH_COUNTER% 1>> "%~dp0logs\serverstart.log" 2>&1 299 | ECHO DEBUG: MC_SERVER_CRASH_YYYYMMDD=%MC_SERVER_CRASH_YYYYMMDD% 1>> "%~dp0logs\serverstart.log" 2>&1 300 | ECHO DEBUG: MC_SERVER_CRASH_HHMMSS=%MC_SERVER_CRASH_HHMMSS% 1>> "%~dp0logs\serverstart.log" 2>&1 301 | ECHO DEBUG: Current directory file listing: 1>> "%~dp0logs\serverstart.log" 2>&1 302 | DIR 1>> "%~dp0logs\serverstart.log" 2>&1 303 | 304 | REM Check for 64-bit OS, not needed since 64-bit java is checked 305 | REM reg query "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" /v PROCESSOR_ARCHITECTURE | find /i "x86" || GOTO CHECKJAVA 1>> "%~dp0logs\serverstart.log" 2>&1 306 | 307 | :CHECKJAVA 308 | ECHO INFO: Checking java installation... 309 | ECHO DEBUG: JAVA version output (java -d64 -version): 1>> "%~dp0logs\serverstart.log" 2>&1 310 | java -d64 -version || GOTO JAVAERROR 1>> "%~dp0logs\serverstart.log" 2>&1 311 | 312 | java -d64 -version 2>&1 | %MC_SYS32%\FIND.EXE "1.8" 1>> "%~dp0logs\serverstart.log" 2>&1 313 | IF %ERRORLEVEL% EQU 0 ( 314 | ECHO INFO: Found 64-bit Java 1.8 1>> "%~dp0logs\serverstart.log" 2>&1 315 | ECHO ...64-bit Java 1.8 found! 1>> "%~dp0logs\serverstart.log" 2>&1 316 | GOTO CHECKFOLDER 317 | ) ELSE ( 318 | GOTO JAVAERROR 319 | ) 320 | 321 | :JAVAERROR 322 | IF NOT %MC_SERVER_IGNORE_JAVA% EQU 0 ( 323 | ECHO WARN: Skipping validation of proper Java install/version... 324 | ECHO IF Java is not installed, too old, or not 64-bit, the server probably won't start/run correctly 325 | ECHO WARN: Skipping validation of Java install... 1>> "%~dp0logs\serverstart.log" 2>&1 326 | GOTO CHECKFOLDER 327 | ) 328 | COLOR CF 329 | ECHO ERROR: Could not find 64-bit Java 1.8 installed or in PATH 1>> "%~dp0logs\serverstart.log" 2>&1 330 | SET MC_SERVER_ERROR_REASON="JavaVersionOrPathError" 331 | CLS 332 | ECHO. 333 | ECHO ERROR: Could not find valid java version installed. 334 | >nul TIMEOUT 1 335 | ECHO 64-bit Java ver 1.8+ is highly recomended. Check here for latest downloads: 336 | ECHO https://java.com/en/download/manual.jsp 337 | ECHO. 338 | >nul TIMEOUT 1 339 | GOTO ERROR 340 | 341 | :CHECKFOLDER 342 | IF NOT %MC_SERVER_RUN_FROM_BAD_FOLDER% EQU 0 ( 343 | ECHO WARN: Skipping check if server directory is in potentially problematic location... 344 | ECHO WARN: Skipping check if server directory is in potentially problematic location... 1>> "%~dp0logs\serverstart.log" 2>&1 345 | GOTO CHECKONLINE 346 | ) 347 | ECHO Checking if current folder is valid... 348 | ECHO INFO: Checking if current folder is valid... 1>> "%~dp0logs\serverstart.log" 2>&1 349 | 350 | REM Check if current directory is in ProgramFiles 351 | IF NOT DEFINED ProgramFiles ( GOTO CHECKPROG86 ) 352 | ECHO.x%CD%x | %MC_SYS32%\FINDSTR.EXE /I /C:"%ProgramFiles%" >nul 353 | REM ECHO Error Level: %ERRORLEVEL% 354 | IF %ERRORLEVEL% EQU 0 ( 355 | SET MC_SERVER_ERROR_REASON=BadFolder-ProgramFiles; 356 | GOTO FOLDERERROR 357 | ) 358 | ECHO.x%~dp0x | %MC_SYS32%\FINDSTR.EXE /I /C:"%ProgramFiles%" >nul 359 | IF %ERRORLEVEL% EQU 0 ( 360 | SET MC_SERVER_ERROR_REASON=BadFolder-ProgramFiles; 361 | GOTO FOLDERERROR 362 | ) 363 | 364 | :CHECKPROG86 365 | IF NOT DEFINED ProgramFiles^(x86^) ( GOTO CHECKSYS ) 366 | ECHO.x%CD%x | %MC_SYS32%\FINDSTR.EXE /I /C:"%ProgramFiles(x86)%" >nul 367 | IF %ERRORLEVEL% EQU 0 ( 368 | SET MC_SERVER_ERROR_REASON=BadFolder-ProgramFiles86; 369 | GOTO FOLDERERROR 370 | ) 371 | ECHO.x%~dp0x | %MC_SYS32%\FINDSTR.EXE /I /C:"%ProgramFiles(x86)%" >nul 372 | IF %ERRORLEVEL% EQU 0 ( 373 | SET MC_SERVER_ERROR_REASON=BadFolder-ProgramFiles86; 374 | GOTO FOLDERERROR 375 | ) 376 | 377 | :CHECKSYS 378 | REM Check if current directory is in SystemRoot 379 | IF NOT DEFINED SystemRoot ( GOTO CHECKTEMP ) 380 | ECHO.x%CD%x | %MC_SYS32%\FINDSTR.EXE /I /C:"%SystemRoot%" >nul 381 | IF %ERRORLEVEL% EQU 0 ( 382 | SET MC_SERVER_ERROR_REASON=BadFolder-System; 383 | GOTO FOLDERERROR 384 | ) 385 | ECHO.x%~dp0x | %MC_SYS32%\FINDSTR.EXE /I /C:"%SystemRoot%" >nul 386 | IF %ERRORLEVEL% EQU 0 ( 387 | SET MC_SERVER_ERROR_REASON=BadFolder-System; 388 | GOTO FOLDERERROR 389 | ) 390 | 391 | :CHECKTEMP 392 | REM Check if current directory is in TEMP 393 | IF NOT DEFINED TEMP ( GOTO CHECKTMP ) 394 | ECHO.x%CD%x | %MC_SYS32%\FINDSTR.EXE /I /C:"%TEMP%" >nul 395 | IF %ERRORLEVEL% EQU 0 ( 396 | SET MC_SERVER_ERROR_REASON=BadFolder-Temp; 397 | GOTO FOLDERERROR 398 | ) 399 | ECHO.x%~dp0x | %MC_SYS32%\FINDSTR.EXE /I /C:"%TEMP%" >nul 400 | IF %ERRORLEVEL% EQU 0 ( 401 | SET MC_SERVER_ERROR_REASON=BadFolder-Temp; 402 | GOTO FOLDERERROR 403 | ) 404 | 405 | :CHECKTMP 406 | IF NOT DEFINED TMP ( GOTO CHECKONLINE ) 407 | ECHO.x%CD%x | %MC_SYS32%\FINDSTR.EXE /I /C:"%TMP%" >nul 408 | IF %ERRORLEVEL% EQU 0 ( 409 | SET MC_SERVER_ERROR_REASON=BadFolder-Temp; 410 | GOTO FOLDERERROR 411 | ) 412 | ECHO.x%~dp0x | %MC_SYS32%\FINDSTR.EXE /I /C:"%TMP%" >nul 413 | IF %ERRORLEVEL% EQU 0 ( 414 | SET MC_SERVER_ERROR_REASON=BadFolder-Temp; 415 | GOTO FOLDERERROR 416 | ) 417 | ) 418 | GOTO CHECKONLINE 419 | 420 | :FOLDERERROR 421 | ECHO WARN: Running from "Program Files," "Temporary," or "System" folders can lead to permissions issues and data loss 422 | ECHO WARN: If you want to do this anyway, you need change script setting MC_SERVER_RUN_FROM_BAD_FOLDER to 1 423 | ECHO WARN: Running from "Program Files," "Temporary," or "System" folders can lead to permissions issues and data loss 1>> "%~dp0logs\serverstart.log" 2>&1 424 | ECHO WARN: If you want to do this anyway, you need change script setting MC_SERVER_RUN_FROM_BAD_FOLDER to 1 1>> "%~dp0logs\serverstart.log" 2>&1 425 | GOTO ERROR 426 | 427 | :CHECKONLINE 428 | IF NOT %MC_SERVER_IGNORE_OFFLINE% EQU 0 ( 429 | ECHO Skipping internet connectivity check... 430 | ECHO WARN: Skipping internet connectivity check... 1>> "%~dp0logs\serverstart.log" 2>&1 431 | GOTO CHECKFILES 432 | ) 433 | 434 | ECHO Checking for basic internet connectivity... 435 | ECHO INFO: Checking for basic internet connectivity... 1>> "%~dp0logs\serverstart.log" 2>&1 436 | 437 | REM Try with Google DNS 438 | %MC_SYS32%\PING.EXE -n 2 -w 1000 8.8.8.8 | %MC_SYS32%\FIND.EXE "TTL=" 1>> "%~dp0logs\serverstart.log" 2>&1 439 | IF %ERRORLEVEL% EQU 0 ( 440 | SET MC_SERVER_TMP_FLAG=0 441 | ECHO INFO: Ping of "8.8.8.8" Successfull 1>> "%~dp0logs\serverstart.log" 2>&1 442 | ) ELSE ( 443 | SET MC_SERVER_TMP_FLAG=1 444 | ECHO WARN: Ping of "8.8.8.8" Failed 1>> "%~dp0logs\serverstart.log" 2>&1 445 | ) 446 | 447 | REM If Google ping failed try one more time with L3 just in case 448 | IF MC_SERVER_TMP_FLAG EQU 1 ( 449 | %MC_SYS32%\PING.EXE -n 2 -w 1000 4.2.2.1 | %MC_SYS32%\FIND.EXE "TTL=" 1>> "%~dp0logs\serverstart.log" 2>&1 450 | IF %ERRORLEVEL% EQU 0 ( 451 | SET MC_SERVER_TMP_FLAG=0 452 | INFO: Ping of "4.4.2.1" Successfull 1>> "%~dp0logs\serverstart.log" 2>&1 453 | ) ELSE ( 454 | SET MC_SERVER_TMP_FLAG=1 455 | ECHO WARN: Ping of "4.4.2.1" Failed 1>> "%~dp0logs\serverstart.log" 2>&1 456 | ) 457 | ) 458 | 459 | REM Possibly no internet connection... 460 | IF MC_SERVER_TMP_FLAG EQU 1 ( 461 | ECHO ERROR: No internet connectivity found 462 | ECHO ERROR: No internet connectivity found 1>> "%~dp0logs\serverstart.log" 2>&1 463 | SET MC_SERVER_ERROR_REASON=NoInternetConnectivity 464 | GOTO ERROR 465 | ) 466 | 467 | :CHECKFILES 468 | ECHO Checking for forge/minecraft binaries... 469 | ECHO INFO: Checking for forge/minecraft binaries... 1>> "%~dp0logs\serverstart.log" 2>&1 470 | 471 | REM Check if forge is already installed 472 | IF NOT EXIST "%~dp0*forge*%MC_SERVER_FORGEVER%*universal*.jar" ( 473 | ECHO FORGE %MC_SERVER_FORGEVER% binary not found, re-installing... 474 | ECHO INFO: FORGE %MC_SERVER_FORGEVER% not found, re-installing... 1>> "%~dp0logs\serverstart.log" 2>&1 475 | GOTO INSTALLSTART 476 | ) 477 | 478 | REM Check if Minecraft JAR is already downloaded 479 | IF NOT EXIST "%~dp0*minecraft_server.%MC_SERVER_MCVER%.jar" ( 480 | ECHO Minecraft binary not found, re-installing Forge... 481 | ECHO INFO: Minecraft binary not found, re-installing Forge... 1>> "%~dp0logs\serverstart.log" 2>&1 482 | GOTO INSTALLSTART 483 | ) 484 | 485 | REM Check if Libraries are already downloaded 486 | IF NOT EXIST "%~dp0libraries" ( 487 | ECHO Libraries folder not found, re-installing Forge... 488 | ECHO INFO: Libraries folder not found, re-installing Forge... 1>> "%~dp0logs\serverstart.log" 2>&1 489 | GOTO INSTALLSTART 490 | ) 491 | 492 | REM Sponge? 493 | IF %MC_SERVER_SPONGE% EQU 1 ( 494 | ECHO. 495 | ECHO. **** WARNING **** 496 | ECHO SPONGE has been enabled in settings.cfg 497 | ECHO Using Sponge with this modpack is experimental and can cause unexpected problems 498 | ECHO **** USE SPONGE AT YOUR OWN RISK **** 499 | ECHO SPONGE has been enabled in settings.cfg -- this is experimental and can cause unexpected problems USE AT YOUR OWN RISK 1>> "%~dp0logs\serverstart.log" 2>&1 500 | ECHO. 501 | REM create "/mods/" folder if it doesn't exist 502 | IF NOT EXIST "%~dp0mods" ( 503 | ECHO Mods folder not found, creating it 504 | ECHO INFO: Mods folder not found, creating it 1>> "%~dp0logs\serverstart.log" 2>&1 505 | MKDIR "%~dp0mods" 1>> "%~dp0logs\serverstart.log" 2>&1 506 | ) 507 | REM Check for spongeforge jar in /mods/ 508 | IF NOT EXIST "%~dp0mods/*spongeforge*%MC_SERVER_MCVER%*.jar" ( 509 | ECHO SpongeForge JAR for not found in "mods" folder... 510 | ECHO INFO: SpongeForge JAR not found in "mods" folder 1>> "%~dp0logs\serverstart.log" 2>&1 511 | GOTO DOWNLOADSPONGE 512 | ) 513 | REM Check for spongeforge bootstrapper 514 | REM IF NOT EXIST "%~dp0*sponge*bootstrap*.jar" ( 515 | REM ECHO SpongeBootstrap loader not found... 516 | REM ECHO INFO: SpongeForge Bootstrap loader not found 1>> "%~dp0logs\serverstart.log" 2>&1 517 | REM GOTO DOWNLOADSPONGE 518 | REM ) 519 | ) 520 | 521 | REM set absolute paths for binary JARs 522 | (FOR /f "usebackq tokens=* delims=*" %%x in (`dir ^"*forge*%MC_SERVER_FORGEVER%*universal*.jar^" /B /O:-D`) DO SET "MC_SERVER_FORGE_JAR=%%x" & GOTO CHECKFILES1) 1>> "%~dp0logs\serverstart.log" 2>&1 523 | 524 | :CHECKFILES1 525 | (FOR /f "usebackq tokens=* delims=*" %%x in (`dir ^"*forge*%MC_SERVER_FORGEVER%*universal*.jar^" /B /O:-D`) DO SET "MC_SERVER_SPONGE_BOOT=%%x" & GOTO CHECKFILES2) 1>> "%~dp0logs\serverstart.log" 2>&1 526 | 527 | :CHECKFILES2 528 | REM Delete duplicate binary JARs 529 | rem ECHO DEBUG: MC_SERVER_SPONGE_BOOT=%MC_SERVER_SPONGE_BOOT% 1>> "%~dp0logs\serverstart.log" 2>&1 530 | ECHO DEBUG: MC_SERVER_FORGE_JAR=%MC_SERVER_FORGE_JAR% 1>> "%~dp0logs\serverstart.log" 2>&1 531 | rem ATTRIB +R "%MC_SERVER_SPONGE_BOOT%" 1>> "%~dp0logs\serverstart.log" 2>&1 || ECHO INFO: No Sponge Jar present to read-only 1>> "%~dp0logs\serverstart.log" 2>&1 532 | ATTRIB +R "%MC_SERVER_FORGE_JAR%" 1>> "%~dp0logs\serverstart.log" 2>&1 || ECHO INFO: No Forge Jar present to read-only 1>> "%~dp0logs\serverstart.log" 2>&1 533 | DEL "%~dp0*forge*universal*.jar" /A:-R 1>> "%~dp0logs\serverstart.log" 2>&1 || ECHO INFO: No Sponge Jars present to delete 1>> "%~dp0logs\serverstart.log" 2>&1 534 | REM DEL "%~dp0*sponge*bootstrap*.jar" /A:-R 1>> "%~dp0logs\serverstart.log" 2>&1 || ECHO INFO: No Forge Jars present to delete 1>> "%~dp0logs\serverstart.log" 2>&1 535 | rem ATTRIB -R "%MC_SERVER_SPONGE_BOOT%" 1>> "%~dp0logs\serverstart.log" 2>&1 || ECHO INFO: No Sponge Jar present to UN-read-only 1>> "%~dp0logs\serverstart.log" 2>&1 536 | ATTRIB -R "%MC_SERVER_FORGE_JAR%" 1>> "%~dp0logs\serverstart.log" 2>&1 || ECHO INFO: No Forge Jar present to UN-read-only 1>> "%~dp0logs\serverstart.log" 2>&1 537 | 538 | :STARTSERVER 539 | CLS 540 | IF /i "%1"=="install" (GOTO INSTALLCOMPLETE) 541 | TITLE %MC_SERVER_PACKNAME% Server Running 542 | ECHO. 543 | ECHO. 544 | ECHO Starting %MC_SERVER_PACKNAME% Server... 545 | ECHO INFO: Starting Server... 1>> "%~dp0logs\serverstart.log" 2>&1 546 | COLOR 07 547 | 548 | REM Batch will wait here indefinitely while MC server is running 549 | IF %MC_SERVER_SPONGE% EQU 1 ( 550 | ECHO DEBUG: Attempting to execute [ java %MC_SERVER_JVM_ARGS% -jar "%~dp0%MC_SERVER_SPONGE_BOOT%" nogui ] 551 | ECHO DEBUG: Attempting to execute [ java %MC_SERVER_JVM_ARGS% -jar "%~dp0%MC_SERVER_SPONGE_BOOT%" nogui ] 1>> "%~dp0logs\serverstart.log" 2>&1 552 | COLOR 553 | IF %MC_SERVER_HIGH_PRIORITY% EQU 1 ( 554 | START /B /I /WAIT /HIGH java %MC_SERVER_JVM_ARGS% -jar "%~dp0%MC_SERVER_SPONGE_BOOT%" nogui 555 | ) ELSE ( 556 | java %MC_SERVER_JVM_ARGS% -jar "%~dp0%MC_SERVER_SPONGE_BOOT%" nogui 557 | ) 558 | ) ELSE ( 559 | ECHO DEBUG: Disabling any spongeforge jar in \mods\ because USE_SPONGE is disabled in settings.cfg 1>> "%~dp0logs\serverstart.log" 2>&1 560 | (FOR /f "tokens=* delims=*" %%x in ('dir "%~dp0mods\*spongeforge*.jar" /B /O:-D') DO MOVE /Y "%~dp0mods\%%x" "%%x.disabled") 1>> "%~dp0logs\serverstart.log" 2>&1 561 | ECHO DEBUG: Attempting to execute [ java %MC_SERVER_JVM_ARGS% -jar "%~dp0%MC_SERVER_FORGE_JAR%" nogui ] 562 | ECHO DEBUG: Attempting to execute [ java %MC_SERVER_JVM_ARGS% -jar "%~dp0%MC_SERVER_FORGE_JAR%" nogui ] 1>> "%~dp0logs\serverstart.log" 2>&1 563 | COLOR 564 | IF %MC_SERVER_HIGH_PRIORITY% EQU 1 ( 565 | START /B /I /WAIT /HIGH java %MC_SERVER_JVM_ARGS% -jar "%~dp0%MC_SERVER_FORGE_JAR%" nogui 566 | ) ELSE ( 567 | java %MC_SERVER_JVM_ARGS% -jar "%~dp0%MC_SERVER_FORGE_JAR%" nogui 568 | ) 569 | ) 570 | 571 | REM If server is exited or crashes, restart... 572 | REM CLS 573 | ECHO. 574 | ECHO WARN: %MC_SERVER_PACKNAME% Server was stopped (possibly crashed)... 575 | GOTO RESTARTER 576 | 577 | :INSTALLSTART 578 | COLOR 5F 579 | TITLE INSTALLING Forge/Minecraft for %MC_SERVER_PACKNAME% server 580 | ECHO Clearing old files before installing forge/minecraft... 581 | ECHO INFO: Clearing and installing forge/minecraft... 1>> "%~dp0logs\serverstart.log" 2>&1 582 | 583 | REM Just in case there's anything pending or dupe-named before starting... 584 | %MC_SYS32%\bitsadmin.exe /reset 1>> "%~dp0logs\serverstart.log" 2>&1 585 | 586 | (FOR /f "tokens=* delims=*" %%x in ('dir "%~dp0*forge*%MC_SERVER_MCVER%*%MC_SERVER_FORGEVER%*installer.jar" /B /O:-D') DO SET "MC_SERVER_TMP_FLAG=%%x" & GOTO INSTALL1) 1>> "%~dp0logs\serverstart.log" 2>&1 587 | 588 | :INSTALL1 589 | REM Delete old/duplicate installers 590 | ECHO: DEBUG: MC_SERVER_TMP_FLAG=%MC_SERVER_TMP_FLAG% 1>> "%~dp0logs\serverstart.log" 2>&1 591 | ATTRIB +R "%MC_SERVER_TMP_FLAG%" 1>> "%~dp0logs\serverstart.log" 2>&1 || ECHO INFO: No Forge Installer present to read-only 1>> "%~dp0logs\serverstart.log" 2>&1 592 | DEL "%~dp0*forge*installer*.jar*" /A:-R 1>> "%~dp0logs\serverstart.log" 2>&1 || ECHO INFO: No Forge Installers present to delete 1>> "%~dp0logs\serverstart.log" 2>&1 593 | ATTRIB -R "%MC_SERVER_TMP_FLAG%" 1>> "%~dp0logs\serverstart.log" 2>&1 || ECHO INFO: No Forge Installer present to UN-read-only 1>> "%~dp0logs\serverstart.log" 2>&1 594 | SET MC_SERVER_TMP_FLAG= 1>> "%~dp0logs\serverstart.log" 2>&1 595 | 596 | REM Check for existing/included forge-installer and run it instead of downloading 597 | IF EXIST "%~dp0forge-%MC_SERVER_MCVER%-%MC_SERVER_FORGEVER%-installer.jar" ( 598 | ECHO. 599 | ECHO. 600 | ECHO Existing forge installer already found... 601 | ECHO Default is to use this installer and not re-download 602 | GOTO RUNINSTALLER 603 | ) 604 | 605 | IF NOT %MC_SERVER_IGNORE_OFFLINE% EQU 0 ( 606 | ECHO Skipping forge server online check... 607 | ECHO WARN: Skipping forge server online check... 1>> "%~dp0logs\serverstart.log" 2>&1 608 | GOTO FORGEFILEPREP 609 | ) 610 | 611 | REM Ping minecraftforge before attempting download 612 | %MC_SYS32%\PING.EXE -n 2 -w 1000 minecraftforge.net | %MC_SYS32%\FIND.EXE "TTL=" 1>> "%~dp0logs\serverstart.log" 2>&1 613 | IF %ERRORLEVEL% EQU 0 ( 614 | ECHO INFO: Ping of "minecraftforge.net" Successfull 1>> "%~dp0logs\serverstart.log" 2>&1 615 | ) ELSE ( 616 | ECHO ERROR: Could not reach minecraftforge.net! Possible firewall or internet issue? 617 | ECHO ERROR: Could not reach minecraftforge.net 1>> "%~dp0logs\serverstart.log" 2>&1 618 | SET MC_SERVER_ERROR_REASON=NoInternetConnectivityMinecraftForgeNet 619 | GOTO ERROR 620 | ) 621 | 622 | :FORGEFILEPREP 623 | DEL /F /Q "%~dp0*forge*.html" 1>> "%~dp0logs\serverstart.log" 2>&1 || ECHO INFO: No forge-index to delete 1>> "%~dp0logs\serverstart.log" 2>&1 624 | DEL /F /Q "%~dp0*forge*universal*" 1>> "%~dp0logs\serverstart.log" 2>&1 || ECHO INFO: No forge-universal to delete 1>> "%~dp0logs\serverstart.log" 2>&1 625 | DEL /F /Q "%~dp0*tmp-forgeinstaller.jar" 1>> "%~dp0logs\serverstart.log" 2>&1 || ECHO INFO: No forge-installer to delete 1>> "%~dp0logs\serverstart.log" 2>&1 626 | DEL /F /Q "%~dp0*minecraft*server*%MC_SERVER_MCVER%*.jar" 1>> "%~dp0logs\serverstart.log" 2>&1 || ECHO INFO: No minecraft binary to delete 1>> "%~dp0logs\serverstart.log" 2>&1 627 | RMDIR /S /Q "%~dp0libraries" 1>> "%~dp0logs\serverstart.log" 2>&1 || ECHO INFO: No Libraries folder to delete 1>> "%~dp0logs\serverstart.log" 2>&1 628 | 629 | ECHO. 630 | ECHO. 631 | ECHO Downloading FORGE (step 1 of 2). This can take several minutes, please be patient... 632 | 633 | REM Check if direct forge URL is specified in config 634 | IF NOT %MC_SERVER_FORGEURL%==DISABLE ( 635 | ECHO Attempting to download "%MC_SERVER_FORGEURL%... this can take a moment, please wait." 636 | GOTO DOWNLOADINSTALLER 637 | ) 638 | 639 | SET MC_SERVER_TMP_FLAG=0 640 | 641 | :FETCHHTML 642 | REM Download Forge Download Index HTML to parse the URL for the direct download 643 | ECHO INFO: Fetching index html from forge ^( https://files.minecraftforge.net/maven/net/minecraftforge/forge/index_%MC_SERVER_MCVER%.html ^) 1>> "%~dp0logs\serverstart.log" 2>&1 644 | %MC_SYS32%\bitsadmin.exe /rawreturn /nowrap /transfer dlforgehtml /download /priority FOREGROUND "https://files.minecraftforge.net/maven/net/minecraftforge/forge/index_%MC_SERVER_MCVER%.html" "%~dp0forge-%MC_SERVER_MCVER%.html" 1>> "%~dp0logs\serverstart.log" 2>&1 645 | 646 | IF NOT EXIST "%~dp0forge-%MC_SERVER_MCVER%.html" ( 647 | IF "%MC_SERVER_TMP_FLAG%"=="0" ( 648 | ECHO Something went wrong, trying again... 649 | SET MC_SERVER_TMP_FLAG=1 650 | GOTO FETCHHTML 651 | ) ELSE ( 652 | SET MC_SERVER_ERROR_REASON=ForgeIndexNotFound 653 | GOTO ERROR 654 | ) 655 | ) 656 | 657 | REM Simple search for matching text to make sure we got the correct webpage/html (and not a 404, for example) 658 | REM ECHO DEBUG: Checking simple pattern match for forge ver to validate HTML... 1>> "%~dp0logs\serverstart.log" 2>&1 659 | REM FIND /I "%MC_SERVER_FORGEVER%" forge-%MC_SERVER_MCVER%.html 1>> "%~dp0logs\serverstart.log" 2>&1 || ( 660 | REM IF %MC_SERVER_TMP_FLAG% LEQ 0 ( 661 | REM ECHO Something wrong with Forge download part 1 of 2 662 | REM ECHO Something wrong with Forge download part 1 of 2 1>> "%~dp0logs\serverstart.log" 2>&1 663 | REM SET MC_SERVER_TMP_FLAG=1 664 | REM DEL /F /Q "%~dp0*forge-index.html" 1>> "%~dp0logs\serverstart.log" 2>&1 || ECHO INFO: No forge-index to delete 1>> "%~dp0logs\serverstart.log" 2>&1 665 | REM GOTO FETCHHTML 666 | REM ) ELSE ( 667 | REM ECHO HTML Download failed a second time... stopping. 668 | REM ECHO ERROR: HTML Download failed a second time... stopping. 1>> "%~dp0logs\serverstart.log" 2>&1 669 | REM SET MC_SERVER_ERROR_REASON=ForgeDownloadURLNotFound 670 | REM GOTO ERROR 671 | REM ) 672 | REM ) 673 | 674 | REM More complex wannabe-regex (aka magic) 675 | FOR /f tokens^=^5^ delims^=^=^<^>^" %%G in ('%MC_SYS32%\FINDSTR.EXE /ir "https://files.minecraftforge.net/maven/net/minecraftforge/forge/%MC_SERVER_MCVER%-%MC_SERVER_FORGEVER%/forge-%MC_SERVER_MCVER%-%MC_SERVER_FORGEVER%-installer.jar" "%~dp0forge-%MC_SERVER_MCVER%.html"') DO SET MC_SERVER_FORGEURL=%%G & GOTO FETCHHTML1 676 | 677 | :FETCHHTML1 678 | IF "%MC_SERVER_FORGEURL%"=="%MC_SERVER_FORGEURL:installer.jar=%" ( 679 | IF "%MC_SERVER_TMP_FLAG%"=="0" ( 680 | ECHO Something went wrong, trying again... 681 | SET MC_SERVER_TMP_FLAG=1 682 | GOTO FETCHHTML 683 | ) ELSE ( 684 | SET MC_SERVER_ERROR_REASON=ForgeDownloadURLNotFound 685 | GOTO ERROR 686 | ) 687 | ) 688 | 689 | ECHO Downloading FORGE (step 2 of 2). This can take several minutes, please be patient... 690 | SET MC_SERVER_TMP_FLAG=0 691 | 692 | :DOWNLOADINSTALLER 693 | REM Attempt to download installer to a temp download 694 | ECHO DEBUG: Attempting to download "%MC_SERVER_FORGEURL%" 1>> "%~dp0logs\serverstart.log" 2>&1 695 | %MC_SYS32%\bitsadmin.exe /rawreturn /nowrap /transfer dlforgeinstaller /download /priority FOREGROUND %MC_SERVER_FORGEURL% "%~dp0tmp-forgeinstaller.jar" 1>> "%~dp0logs\serverstart.log" 2>&1 696 | 697 | REM Check that temp-download installer was downloaded 698 | IF NOT EXIST "%~dp0tmp-forgeinstaller.jar" ( 699 | IF "%MC_SERVER_TMP_FLAG%"=="0" ( 700 | ECHO Something wrong with download 2 of 2 - FORGE installer, trying again... 701 | ECHO Something wrong with download 2 of 2 - FORGE installer, trying again... 1>> "%~dp0logs\serverstart.log" 2>&1 702 | SET MC_SERVER_TMP_FLAG=1 703 | GOTO DOWNLOADINSTALLER 704 | ) ELSE ( 705 | ECHO FORGE Installer download failed a second time... stopping. 706 | ECHO ERROR: FORGE Installer download failed a second time... stopping. 1>> "%~dp0logs\serverstart.log" 2>&1 707 | SET MC_SERVER_ERROR_REASON=ForgeInstallerDownloadFailed 708 | GOTO ERROR 709 | ) 710 | ) 711 | 712 | REM Rename temp installer to proper installer, replacing one that was there already 713 | DEL /F /Q "%~dp0forge-%MC_SERVER_MCVER%-%MC_SERVER_FORGEVER%-installer.jar" 1>> "%~dp0logs\serverstart.log" 2>&1 714 | MOVE /Y "%~dp0tmp-forgeinstaller.jar" "forge-%MC_SERVER_MCVER%-%MC_SERVER_FORGEVER%-installer.jar" 1>> "%~dp0logs\serverstart.log" 2>&1 715 | ECHO Download complete. 716 | 717 | :RUNINSTALLER 718 | 719 | REM Create default server.properties and eula.txt files 720 | IF NOT EXIST "%~dp0server.properties" ( 721 | ECHO Could not find server.properties, creating initial copy... 722 | ECHO INFO: server.properties not found... populating default 723 | ( 724 | ECHO view-distance=8 725 | ECHO allow-flight=true 726 | ECHO level-type=%MC_SERVER_WORLDTYPE% 727 | ECHO snooper-enabled=false 728 | ECHO max-tick-time=90000 729 | ECHO motd=%MC_SERVER_PACKNAME% 730 | ) >"%~dp0server.properties" 731 | ) 732 | IF NOT EXIST "%~dp0eula.txt" ( 733 | ECHO Could not find eula.txt, creating initial copy... 734 | ECHO INFO: eula.txt not found... populating default 735 | ECHO eula=false>>"%~dp0eula.txt" 736 | ) 737 | 738 | ECHO. 739 | ECHO Installing Forge now, please wait... 740 | ECHO INFO: Starting Forge install now, details below: 1>> "%~dp0logs\serverstart.log" 2>&1 741 | java -jar "%~dp0forge-%MC_SERVER_MCVER%-%MC_SERVER_FORGEVER%-installer.jar" --installServer 1>> "%~dp0logs\serverstart.log" 2>&1 742 | 743 | REM TODO: CHECKS TO VALIDATE SUCCESSFUL INSTALL 744 | 745 | REM File cleanup 746 | DEL /F /Q "%~dp0tmp-forgeinstaller.jar" 1>> "%~dp0logs\serverstart.log" 2>&1 747 | DEL /F /Q "%~dp0forge-%MC_SERVER_MCVER%.html" 1>> "%~dp0logs\serverstart.log" 2>&1 748 | 749 | :INSTALLCOMPLETE 750 | COLOR 2F 751 | ECHO. 752 | ECHO. 753 | ECHO. 754 | ECHO ======================================================== 755 | ECHO %MC_SERVER_PACKNAME% Server Files are now ready! 756 | ECHO ======================================================== 757 | ECHO INFO: Download/Install complete... 1>> "%~dp0logs\serverstart.log" 2>&1 758 | >nul TIMEOUT 1 759 | ECHO Download/Install of Forge and Minecraft binaries was sucessful. 760 | ECHO. 761 | >nul TIMEOUT 3 762 | IF /i "%1"=="install" ( 763 | ECHO "install" parameter was passed to script now exiting without starting the server... 764 | ECHO You can use this same script without the "install" parameter to run the server files or 765 | ECHO by manually starting the forge JAR with Java or uploading to your hosting service 766 | ECHO WARN: "install" paremeter passed to script, exiting after install and NOT starting server 1>> "%~dp0logs\serverstart.log" 2>&1 767 | ECHO. 768 | GOTO CLEANUP 769 | ) ELSE ( 770 | GOTO BEGIN 771 | ) 772 | 773 | :DOWNLOADSPONGE 774 | REM Auto-Download not implemented yet, and might not ever be 775 | REM Problems with scraping github for link for bootsreapper were problematic 776 | 777 | REM ---Rename any spongeforge*.jar to .jar.disabled 778 | REM (FOR /f "tokens=* delims=*" %%x in ('dir "%~dp0mods\*spongeforge*.jar" /B /O:-D') DO MOVE /Y "%%x" "%%x.disabled") 1>> "%~dp0logs\serverstart.log" 2>&1 779 | REM ---Rename any sponge*bootstrap*.jar to .jar.disabled 780 | REM (FOR /f "tokens=* delims=*" %%x in ('dir "%~dp0*sponge*bootstrap*.jar" /B /O:-D') DO MOVE /Y "%~dp0%%x" "%%x.disabled") 1>> "%~dp0logs\serverstart.log" 2>&1 781 | REM ---Download spongeforge index to parse for jar download 782 | REM bitsadmin /rawreturn /nowrap /transfer dlspongehtml /download /priority FOREGROUND "http://files.minecraftforge.net/maven/org/spongepowered/spongeforge/index_%MC_SERVER_MCVER%.html" "%~dp0spongeforge-%MC_SERVER_MCVER%.html" 1>> "%~dp0logs\serverstart.log" 2>&1 783 | REM ---Download sponge bootstrap html to parse for jar download 784 | REM bitsadmin /rawreturn /nowrap /transfer dlspongebootstrap /download /priority FOREGROUND "https://api.github.com/repos/simon816/spongebootstrap/releases/latest" "%~dp0spongebootstrap.html" 1>> "%~dp0logs\serverstart.log" 2>&1 785 | REM ---Find latest bootstrap download and save to var 786 | REM FOR /f tokens^=* delims^=^" %%F in ('findstr /ir "https:\/\/github.*releases.*Bootstrap.*\.jar" "%~dp0spongebootstrap.html"') DO ( 787 | REM SET "MC_SERVER_SPONGEBOOTSTRAPURL=%%F" 788 | REM FOR /f tokens^=^30 delims^=^/ %%B in ("%%G") DO ECHO Bootstrap Filename: %%B 789 | REM ---Find latest SpongeForge download and save to var http://files.minecraftforge.net/maven/org/spongepowered/spongeforge/1.10.2-2281-5.2.0-BETA-2274/spongeforge-1.10.2-2281-5.2.0-BETA-2274.jar 790 | REM FOR /f tokens^=* delims^=^" %%G in ('findstr /ir "https:\/\/files.*%MC_SERVER_MCVER%.*%MC_SERVER_FORGESHORT%.*[0-9]*\.jar" "%~dp0spongeforge-%MC_SERVER_MCVER%.html"') DO ( 791 | REM SET "MC_SERVER_SPONGEURL=%%G" 792 | REM FOR /f tokens^=^30 delims^=^/ %%S in ("%%G") DO ECHO SpongeForge Filename: %%S 793 | REM ) 794 | REM ECHO DEBUG: Attempting to download "%MC_SERVER_SPONGEBOOTSTRAPURL%" 1>> "%~dp0logs\serverstart.log" 2>&1 795 | REM bitsadmin /rawreturn /nowrap /transfer dlforgeinstaller /download /priority FOREGROUND %MC_SERVER_SPONGEBOOTSTRAPURL% "%~dp0%%B" 1>> "%~dp0logs\serverstart.log" 2>&1 796 | REM ECHO DEBUG: Attempting to download "%MC_SERVER_SPONGEURL%" 1>> "%~dp0logs\serverstart.log" 2>&1 797 | REM bitsadmin /rawreturn /nowrap /transfer dlforgeinstaller /download /priority FOREGROUND %MC_SERVER_SPONGEURL% "%~dp0%%S" 1>> "%~dp0logs\serverstart.log" 2>&1 798 | 799 | CLS 800 | TITLE ERROR! SPONGE FILES NOT FOUND!! (ServerStart) 801 | COLOR cf 802 | ECHO. 803 | ECHO **** ERROR **** 804 | ECHO SPONGE has been enabled in settings.cfg but necessary files were not found... 805 | ECHO. 806 | ECHO To use Sponge: 807 | ECHO 1) "MODS" folder must have a SpongeForge JAR matching Forge %MC_SERVER_FORGESHORT% 808 | REM ECHO 2) SpongeBootstrap JAR must be present in same folder as Forge "universal" 809 | ECHO. 810 | ECHO **** PLEASE NOTE **** 811 | ECHO YOU MAY NOT RECIEVE SUPPORT from modpack devs if you use Sponge 812 | ECHO Use at your own risk OR DISABLE SPONGE in settings.cfg 813 | ECHO. 814 | TIMEOUT 1 >nul 815 | COLOR 4f 816 | TIMEOUT 1 >nul 817 | COLOR cf 818 | TIMEOUT 1 >nul 819 | COLOR 4f 820 | TIMEOUT 1 >nul 821 | COLOR cf 822 | TIMEOUT 1 >nul 823 | COLOR 0c 824 | PAUSE 825 | GOTO CLEANUP 826 | 827 | :ERROR 828 | COLOR cf 829 | TITLE ERROR - "%MC_SERVER_ERROR_REASON%" - Script Stopped 830 | ECHO. 831 | ECHO **** ERROR **** 832 | ECHO There was an Error, Code: "%MC_SERVER_ERROR_REASON%" 833 | ECHO ERROR: Error flagged, reason is: "%MC_SERVER_ERROR_REASON%" 1>> "%~dp0logs\serverstart.log" 2>&1 834 | ECHO. 835 | TIMEOUT 1 >nul 836 | COLOR 4f 837 | TIMEOUT 1 >nul 838 | COLOR cf 839 | TIMEOUT 1 >nul 840 | COLOR 4f 841 | TIMEOUT 1 >nul 842 | COLOR cf 843 | TIMEOUT 1 >nul 844 | COLOR 0c 845 | GOTO CLEANUP 846 | 847 | :RESTARTER 848 | COLOR 6F 849 | REM Quick-check EULA before commencing full restarter logic 850 | >nul %MC_SYS32%\FIND.EXE /I "eula=true" "%~dp0eula.txt" || ( 851 | TITLE ERROR: EULA.TXT Must be updated before %MC_SERVER_PACKNAME% server can start 852 | CLS 853 | ECHO. 854 | ECHO Could not find "eula=true" in eula.txt file 855 | ECHO Please edit and save the EULA file before continuing. 856 | ECHO. 857 | PAUSE 858 | GOTO STARTSERVER 859 | ) 860 | 861 | ECHO ERROR: At %MC_SERVER_CRASH_YYYYMMDD%:%MC_SERVER_CRASH_HHMMSS% Server has stopped. 1>> "%~dp0logs\serverstart.log" 2>&1 862 | ECHO At %MC_SERVER_CRASH_YYYYMMDD%:%MC_SERVER_CRASH_HHMMSS% Server has stopped. 863 | ECHO Server has %MC_SERVER_CRASH_COUNTER% consecutive stops, each within %MC_SERVER_CRASH_TIMER% seconds of eachother... 864 | ECHO DEBUG: Server has %MC_SERVER_CRASH_COUNTER% consecutive stops, each within %MC_SERVER_CRASH_TIMER% seconds of eachother... 1>> "%~dp0logs\serverstart.log" 2>&1 865 | ECHO. 866 | 867 | REM Arithmetic to check DAYS since last crash 868 | REM Testing working in USA region. Hoping other regional formats don't mess it up 869 | SET /a MC_SERVER_TMP_FLAG="%date:~10,4%%date:~4,2%%date:~7,2%-%MC_SERVER_CRASH_YYYYMMDD%" 870 | 871 | REM If more than one calendar day, reset timer/counter. 872 | REM Yes, this means over midnight it's not accurate. 873 | REM Nobody's perfect. 874 | IF %MC_SERVER_TMP_FLAG% GTR 0 ( 875 | ECHO More than one day since last crash/restart... resetting counter/timer 876 | ECHO INFO: More than one day since last crash/restart... resetting counter/timer 1>> "%~dp0logs\serverstart.log" 2>&1 877 | SET MC_SERVER_CRASH_YYYYMMDD=%date:~10,4%%date:~4,2%%date:~7,2% 878 | SET MC_SERVER_CRASH_HHMMSS=%time:~0,2%%time:~3,2%%time:~6,2% 879 | SET MC_SERVER_CRASH_COUNTER=0 880 | GOTO BEGIN 881 | ) 882 | 883 | REM Arithmetic to check SECONDS since last crash 884 | SET /a MC_SERVER_TMP_FLAG="%time:~0,2%%time:~3,2%%time:~6,2%-%MC_SERVER_CRASH_HHMMSS%" 885 | 886 | REM If more than specified seconds (from config variable), reset timer/counter. 887 | IF %MC_SERVER_TMP_FLAG% GTR %MC_SERVER_CRASH_TIMER% ( 888 | ECHO Last crash/startup was %MC_SERVER_TMP_FLAG%+ seconds ago 889 | ECHO INFO: Last crash/startup was %MC_SERVER_TMP_FLAG%+ seconds ago 1>> "%~dp0logs\serverstart.log" 2>&1 890 | ECHO More than %MC_SERVER_CRASH_TIMER% seconds since last crash/restart... resetting counter/timer 891 | ECHO INFO: More than %MC_SERVER_CRASH_TIMER% seconds since last crash/restart... resetting counter/timer 1>> "%~dp0logs\serverstart.log" 2>&1 892 | SET MC_SERVER_CRASH_YYYYMMDD=%date:~10,4%%date:~4,2%%date:~7,2% 893 | SET MC_SERVER_CRASH_HHMMSS=%time:~0,2%%time:~3,2%%time:~6,2% 894 | SET MC_SERVER_CRASH_COUNTER=0 895 | REM GOTO BEGIN 896 | ) 897 | 898 | REM If we are still here, time difference is within threshold to increment counter 899 | REM Check if already max failures: 900 | IF %MC_SERVER_CRASH_COUNTER% GEQ %MC_SERVER_MAX_CRASH% ( 901 | COLOR cf 902 | SET MC_SERVER_ERROR_REASON=TooManyCrashes:%MC_SERVER_CRASH_COUNTER% 903 | ECHO INFO: Last crash/startup was %MC_SERVER_TMP_FLAG%+ seconds ago 1>> "%~dp0logs\serverstart.log" 2>&1 904 | ECHO. 905 | ECHO. 906 | ECHO =================================================== 907 | ECHO ERROR: Server has stopped/crashed too many times! 908 | ECHO =================================================== 909 | ECHO ERROR: Server has stopped/crashed too many times! 1>> "%~dp0logs\serverstart.log" 2>&1 910 | ECHO. 911 | >nul TIMEOUT 1 912 | ECHO %MC_SERVER_CRASH_COUNTER% Crashes have been counted each within %MC_SERVER_CRASH_TIMER% seconds. 913 | >nul TIMEOUT 1 914 | GOTO ERROR 915 | ) 916 | 917 | REM Still under threshold so lets increment and restart 918 | ECHO INFO: Last crash/startup was %MC_SERVER_TMP_FLAG%+ seconds ago 1>> "%~dp0logs\serverstart.log" 2>&1 919 | SET /a "MC_SERVER_CRASH_COUNTER=%MC_SERVER_CRASH_COUNTER%+1" 920 | SET MC_SERVER_CRASH_YYYYMMDD=%date:~10,4%%date:~4,2%%date:~7,2% 921 | SET MC_SERVER_CRASH_HHMMSS=%time:~0,2%%time:~3,2%%time:~6,2% 922 | 923 | ECHO DEBUG: Total consecutive crash/stops within time threshold: %MC_SERVER_CRASH_COUNTER% 1>> "%~dp0logs\serverstart.log" 2>&1 924 | ECHO. 925 | ECHO. 926 | ECHO. 927 | ECHO. 928 | ECHO Server will re-start *automatically* in less than 30 seconds... 929 | CHOICE /M:"Restart now (Y) or Exit (N)" /T:30 /D:Y 930 | IF %ERRORLEVEL% GEQ 2 ( 931 | ECHO INFO: Server manually stopped before auto-restart 1>> "%~dp0logs\serverstart.log" 2>&1 932 | GOTO CLEANUP 933 | ) ELSE ( 934 | GOTO BEGIN 935 | ) 936 | 937 | :CLEANUP 938 | ECHO WARN: Server startup script is exiting. Dumping current vars: 1>> "%~dp0logs\serverstart.log" 2>&1 939 | ECHO DEBUG: MC_SERVER_MAX_RAM=%MC_SERVER_MAX_RAM% 1>> "%~dp0logs\serverstart.log" 2>&1 940 | ECHO DEBUG: MC_SERVER_FORGE_JAR=%MC_SERVER_FORGE_JAR% 1>> "%~dp0logs\serverstart.log" 2>&1 941 | ECHO DEBUG: MC_SERVER_SPONGE_BOOT=%MC_SERVER_SPONGE_BOOT% 1>> "%~dp0logs\serverstart.log" 2>&1 942 | ECHO DEBUG: MC_SERVER_JVM_ARGS=%MC_SERVER_JVM_ARGS% 1>> "%~dp0logs\serverstart.log" 2>&1 943 | ECHO DEBUG: MC_SERVER_MAX_CRASH=%MC_SERVER_MAX_CRASH% 1>> "%~dp0logs\serverstart.log" 2>&1 944 | ECHO DEBUG: MC_SERVER_CRASH_TIMER=%MC_SERVER_CRASH_TIMER% 1>> "%~dp0logs\serverstart.log" 2>&1 945 | ECHO DEBUG: MC_SERVER_IGNORE_OFFLINE=%MC_SERVER_IGNORE_OFFLINE% 1>> "%~dp0logs\serverstart.log" 2>&1 946 | ECHO DEBUG: MC_SERVER_RUN_FROM_BAD_FOLDER=%MC_SERVER_RUN_FROM_BAD_FOLDER% 1>> "%~dp0logs\serverstart.log" 2>&1 947 | ECHO DEBUG: MC_SERVER_MCVER=%MC_SERVER_MCVER% 1>> "%~dp0logs\serverstart.log" 2>&1 948 | ECHO DEBUG: MC_SERVER_FORGEVER=%MC_SERVER_FORGEVER% 1>> "%~dp0logs\serverstart.log" 2>&1 949 | ECHO DEBUG: MC_SERVER_FORGESHORT=%MC_SERVER_FORGESHORT% 1>> "%~dp0logs\serverstart.log" 2>&1 950 | ECHO DEBUG: MC_SERVER_FORGEURL=%MC_SERVER_FORGEURL% 1>> "%~dp0logs\serverstart.log" 2>&1 951 | ECHO DEBUG: MC_SERVER_HIGH_PRIORITY=%MC_SERVER_HIGH_PRIORITY% 1>> "%~dp0logs\serverstart.log" 2>&1 952 | ECHO DEBUG: MC_SERVER_SPONGE=%MC_SERVER_SPONGE% 1>> "%~dp0logs\serverstart.log" 2>&1 953 | ECHO DEBUG: MC_SERVER_PACKNAME=%MC_SERVER_PACKNAME% 1>> "%~dp0logs\serverstart.log" 2>&1 954 | ECHO DEBUG: MC_SERVER_WORLDTYPE=%MC_SERVER_WORLDTYPE% 1>> "%~dp0logs\serverstart.log" 2>&1 955 | ECHO DEBUG: MC_SERVER_SPONGEURL=%MC_SERVER_SPONGEURL% 1>> "%~dp0logs\serverstart.log" 2>&1 956 | REM ECHO DEBUG: MC_SERVER_SPONGEBOOTSTRAPURL=%MC_SERVER_SPONGEBOOTSTRAPURL% 1>> "%~dp0logs\serverstart.log" 2>&1 957 | ECHO DEBUG: MC_SERVER_ERROR_REASON=%MC_SERVER_ERROR_REASON% 1>> "%~dp0logs\serverstart.log" 2>&1 958 | ECHO DEBUG: MC_SERVER_TMP_FLAG=%MC_SERVER_TMP_FLAG% 1>> "%~dp0logs\serverstart.log" 2>&1 959 | ECHO DEBUG: MC_SERVER_CRASH_COUNTER=%MC_SERVER_CRASH_COUNTER% 1>> "%~dp0logs\serverstart.log" 2>&1 960 | ECHO DEBUG: MC_SERVER_CRASH_YYYYMMDD=%MC_SERVER_CRASH_YYYYMMDD% 1>> "%~dp0logs\serverstart.log" 2>&1 961 | ECHO DEBUG: MC_SERVER_CRASH_HHMMSS=%MC_SERVER_CRASH_HHMMSS% 1>> "%~dp0logs\serverstart.log" 2>&1 962 | ECHO DEBUG: Current directory file listing: 1>> "%~dp0logs\serverstart.log" 2>&1 963 | DIR 1>> "%~dp0logs\serverstart.log" 2>&1 964 | ECHO DEBUG: JAVA version output (java -d64 -version): 1>> "%~dp0logs\serverstart.log" 2>&1 965 | java -d64 -version 1>> "%~dp0logs\serverstart.log" 2>&1 966 | 967 | REM Clear variables -- probably not necessary since we SETLOCAL but doesn't hurt either 968 | SET MC_SERVER_MAX_RAM= 969 | SET MC_SERVER_FORGE_JAR= 970 | SET MC_SERVER_SPONGE_BOOT= 971 | SET MC_SERVER_JVM_ARGS= 972 | SET MC_SERVER_MAX_CRASH= 973 | SET MC_SERVER_CRASH_TIMER= 974 | SET MC_SERVER_IGNORE_OFFLINE= 975 | SET MC_SERVER_RUN_FROM_BAD_FOLDER= 976 | SET MC_SERVER_MCVER= 977 | SET MC_SERVER_FORGEVER= 978 | SET MC_SERVER_FORGESHORT= 979 | SET MC_SERVER_FORGEURL= 980 | SET MC_SERVER_SPONGE= 981 | SET MC_SERVER_HIGH_PRIORITY= 982 | SET MC_SERVER_PACKNAME= 983 | SET MC_SERVER_WORLDTYPE= 984 | SET MC_SERVER_SPONGEURL= 985 | REM SET MC_SERVER_SPONGEBOOTSTRAPURL= 986 | SET MC_SERVER_ERROR_REASON= 987 | SET MC_SERVER_TMP_FLAG= 988 | SET MC_SERVER_CRASH_COUNTER= 989 | SET MC_SERVER_CRASH_YYYYMMDD= 990 | SET MC_SERVER_CRASH_HHMMSS= 991 | 992 | REM Reset bitsadmin in case things got hung or errored 993 | %MC_SYS32%\bitsadmin.exe /reset 1>> "%~dp0logs\serverstart.log" 2>&1 994 | 995 | COLOR 996 | 997 | :EOF 998 | -------------------------------------------------------------------------------- /ServerStart.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #### Minecraft-Forge Server install/launcher script 4 | #### Linux Version 5 | #### 6 | #### Created by: Dijkstra 7 | #### Mascot: Ordinator 8 | #### 9 | #### Originally created for use in "All The Mods" modpacks 10 | #### NO OFFICIAL AFFILIATION WITH MOJANG OR FORGE 11 | #### 12 | #### This script will fetch the appropriate forge installer 13 | #### and run it to install forge AND fetch Minecraft (from Mojang) 14 | #### If Forge and Minecraft are already installed it will skip 15 | #### download/install and launch server directly (with 16 | #### auto-restart-after-crash logic as well) 17 | #### 18 | #### Make sure this is running as BASH 19 | #### You might need to chmod +x before executing 20 | #### 21 | #### IF THERE ARE ANY ISSUES 22 | #### Please make a report on the AllTheMods github: 23 | #### https://github.com/AllTheMods/Server-Scripts 24 | #### with the contents of [logs/serverstart.log] and [installer.log] 25 | #### 26 | #### or come find us on Discord: https://discord.gg/FdFDVWb 27 | #### 28 | 29 | eula_gen(){ 30 | echo "By typing Yes you are indicating your agreement to the Minecraft EULA (https://account.mojang.com/documents/minecraft_eula)." 31 | echo "Please read the EULA linked above" 32 | 33 | export answer="No" 34 | echo "" 35 | read -r -p "Type Yes is agree otherwise type No? " answer 36 | if [[ "$answer" =~ ^([yY][eE][sS]|[yY])+$ ]]; then 37 | echo "INFO: EULA accepted" >>logs/serverstart.log 2>&1 38 | echo "#Minecraft EULA (https://account.mojang.com/documents/minecraft_eula)." > eula.txt 39 | echo "eula=true" >> eula.txt 40 | else 41 | echo "INFO: EULA rejected" >>logs/serverstart.log 2>&1 42 | echo "#Minecraft EULA (https://account.mojang.com/documents/minecraft_eula)." > eula.txt 43 | echo "eula=false" >> eula.txt 44 | exit 0 45 | fi 46 | } 47 | 48 | install_server(){ 49 | echo "Starting install of Forge/Minecraft server binaries" 50 | echo "DEBUG: Starting install of Forge/Minecraft server binaries" >>logs/serverstart.log 51 | 52 | 53 | installers=$(ls forge*"$MC_SERVER_MCVER"*"$MC_SERVER_FORGEVER"*installer.jar 2>>logs/serverstart.log) 54 | if [[ $? == 0 ]]; then 55 | installer=${installers[0]} 56 | echo "DEBUG: Found forge jar: $installer" >>logs/serverstart.log 57 | export answer="y" 58 | if [[ $MC_SERVER_AUTO_RESPOND == 0 ]]; then 59 | read -r -t 8 -p "Installer found. Use it (y) or download again (n)? " answer 60 | fi 61 | if [[ "$answer" =~ ^([yY][eE][sS]|[yY])+$ ]]; then 62 | echo "INFO: Skipping download. Using existing installer.jar" >>logs/serverstart.log 2>&1 63 | echo "Skipping download. Using existing installer.jar" 64 | else 65 | echo "Moving current installer to ./DELETEME" 66 | mkdir -p DELETEME 67 | mv -f "./$installer" ./DELETEME >>logs/serverstart.log 2>&1 68 | installer=0 69 | fi 70 | else 71 | installer=0 72 | fi 73 | 74 | if [[ $installer == 0 ]]; then 75 | echo "DEBUG: no forge installer for MCVER: $MC_SERVER_MCVER and FORGEVER: $MC_SERVER_FORGEVER found" >>logs/serverstart.log 76 | echo "No installer found will try to download it" 77 | 78 | if [ "${MC_SERVER_FORGEURL}" = "DISABLE" ]; then 79 | export MC_SERVER_URL="https://files.minecraftforge.net/maven/net/minecraftforge/forge/${MC_SERVER_MCVER}-${MC_SERVER_FORGEVER}/forge-${MC_SERVER_MCVER}-${MC_SERVER_FORGEVER}-installer.jar" 80 | else 81 | export MC_SERVER_URL="${MC_SERVER_FORGEURL}" 82 | fi 83 | 84 | command - v curl >> /dev/null 2>&1 85 | if [[ $? == 0 ]]; then 86 | echo "DEBUG: (curl) Downloading ${MC_SERVER_URL}" >>logs/serverstart.log 2>&1 87 | curl -OJL "${MC_SERVER_URL}" >>logs/serverstart.log 2>&1 88 | else 89 | command -v wget >> /dev/null 2>&1 90 | if [[ $? == 0 ]]; then 91 | echo "DEBUG: (wget) Downloading ${MC_SERVER_URL}" >>logs/serverstart.log 2>&1 92 | wget -O "forge.$MC_SERVER_MCVER-$MC_SERVER_FORGEVER-installer.jar" "${MC_SERVER_URL}" >>logs/serverstart.log 2>&1 93 | else 94 | echo "Neither wget or curl were found on your system. Please install one and try again" 95 | echo "ERROR: Neither wget or curl were found" >>logs/serverstart.log 2>&1 96 | exit 1 97 | fi 98 | fi 99 | fi 100 | 101 | installers=$(ls forge*"$MC_SERVER_MCVER"*"$MC_SERVER_FORGEVER"*installer.jar 2>>logs/serverstart.log) 102 | if [[ $? -eq 0 ]] ; then 103 | installer=${installers[0]} 104 | export MC_SERVER_INSTALLER=$installer 105 | echo "Moving unneeded files/folders to ./DELETEME" 106 | { 107 | echo "INFO: Moving unneeded files/folders to ./DELETEME" 108 | rm -rf ./DELETEME 109 | mv -f ./asm ./DELETEME 110 | mv -f ./libraries ./DELETEME 111 | mv -f ./library ./DELETEME 112 | mv -f ./minecraft_server*.jar ./DELETEME 113 | mv -f ./forge*universal.jar ./DELETEME 114 | mv -f ./OpenComputersMod*lua* ./DELETEME 115 | } >>logs/serverstart.log 2>&1 116 | echo "Installing Forge Server, please wait..." 117 | echo "INFO: Installing Forge Server" >>logs/serverstart.log 2>&1 118 | "$MC_SERVER_JAVA" -jar "$installer" --installServer >>logs/serverstart.log 2>&1 119 | 120 | else 121 | echo "Forge installer did not download" 122 | echo "ERROR: Forge installer did not download" >>logs/serverstart.log 2>&1 123 | exit 1 124 | fi 125 | } 126 | 127 | # Make sure users aren't trying to run script via sh directly (won't work) 128 | if [ ! "$BASH_VERSION" ] ; then 129 | echo "Please do not use sh to run this script ($0). Use bash instead (or execute it directly)" 1>&2 130 | exit 1 131 | fi 132 | 133 | #Checks what system the script is being run under 134 | case "$(uname -s)" in 135 | Linux*) MC_SERVER_environment=Linux;; 136 | Darwin*) MC_SERVER_environment=Mac;; 137 | CYGWIN*) MC_SERVER_environment=Cygwin;; 138 | MINGW*) MC_SERVER_environment=MinGw;; 139 | *) MC_SERVER_environment="UNKNOWN:$(uname -s)" 140 | esac 141 | 142 | #Makes sure that the script is being ran from the server directory 143 | cd "${0%/*}" || exit 144 | mkdir -p logs 145 | 146 | echo "INFO: Starting script at $(date -u +%Y-%m-%d_%H:%M:%S)" >logs/serverstart.log 147 | 148 | #Loading settings 149 | 150 | #Default Settings 151 | export MC_SERVER_MAX_RAM=5G 152 | export MC_SERVER_GAME_ARGS=nogui 153 | export MC_SERVER_JAVA_ARGS='-server -XX:+AggressiveOpts -XX:ParallelGCThreads=3 -XX:+UseConcMarkSweepGC -XX:+UnlockExperimentalVMOptions -XX:+UseParNewGC -XX:+ExplicitGCInvokesConcurrent -XX:MaxGCPauseMillis=10 -XX:GCPauseIntervalMillis=50 -XX:+UseFastAccessorMethods -XX:+OptimizeStringConcat -XX:NewSize=84m -XX:+UseAdaptiveGCBoundary -XX:NewRatio=3' 154 | export MC_SERVER_CRASH_COUNT=5 155 | export MC_SERVER_CRASH_TIMER=600 156 | export MC_SERVER_JAVA_PATH=DISABLE 157 | export MC_SERVER_RUN_FROM_BAD_FOLDER=0 158 | export MC_SERVER_IGNORE_OFFLINE=0 159 | export MC_SERVER_IGNORE_JAVA_CHECK=0 160 | export MC_SERVER_USE_SPONGE=0 161 | export MC_SERVER_HIGH_CPU_PRIORITY=0 162 | export MC_SERVER_JMX_ENABLE=0 163 | export MC_SERVER_JMX_PORT=9010 164 | export MC_SERVER_JMX_HOST=127.0.0.1 165 | export MC_SERVER_MODPACK_NAME=PACK NAME 166 | export MC_SERVER_DEFAULT_WORLD_TYPE=BIOMESOP 167 | export MC_SERVER_MCVER=1.12.2 168 | export MC_SERVER_FORGEVER=14.23.5.2811 169 | export MC_SERVER_FORGEURL=DISABLE 170 | export MC_SERVER_AUTO_RESPOND=0 171 | export MC_SERVER_INSTALL_ONLY=0 172 | 173 | #Loading setting.cfg 174 | if [ -f ./settings.cfg ]; then 175 | #Read the config file line by line 176 | while IFS=$'\n\r' read -r line || [[ -n "$line" ]]; do 177 | #Fliters out comments and empty lines 178 | if [[ ${line:0:1} != ';' ]] && [[ $line = *[!\ ]* ]]; then 179 | var="MC_SERVER_"$(echo "$line" | cut -d '=' -f 1) 180 | value=$(echo "$line" | cut -d '=' -f 2-) 181 | export "$var"="$value" 182 | fi 183 | done < ./settings.cfg 184 | else 185 | echo "Failed to find settings file default settings will be used may cause issues" 186 | echo "WARN: Failed to find settings.cfg" >>logs/serverstart.log 187 | fi 188 | 189 | while :; do 190 | case $1 in 191 | -a|--auto) export MC_SERVER_AUTO_RESPOND=1 192 | ;; 193 | -i|--install|install) export MC_SERVER_INSTALL_ONLY=1 194 | ;; 195 | *) break 196 | esac 197 | shift 198 | done 199 | 200 | export MC_SERVER_FORGESHORT=${MC_SERVER_FORGEVER: - 4} 201 | 202 | if [[ "$MC_SERVER_JAVA_PATH" == "DISABLE" ]]; then 203 | export MC_SERVER_JAVA=java 204 | else 205 | command -v $MC_SERVER_JAVA_PATH/java >/dev/null 206 | if [[ $? == "0" ]]; then 207 | export MC_SERVER_JAVA=$MC_SERVER_JAVA_PATH/java 208 | else 209 | echo "Could not find java if path in given in settings using the deflut option" 210 | echo "WARN: Could not find java if path in given in settings" >>logs/serverstart.log 211 | export MC_SERVER_JAVA=java 212 | fi 213 | fi 214 | { 215 | echo "DEBUG: Dumping starting variables: " 216 | echo "DEBUG: MC_SERVER_MAX_RAM=$MC_SERVER_MAX_RAM" 217 | echo "DEBUG: MC_SERVER_GAME_ARGS=$MC_SERVER_GAME_ARGS" 218 | echo "DEBUG: MC_SERVER_JAVA_ARGS=$MC_SERVER_JAVA_ARGS" 219 | echo "DEBUG: MC_SERVER_CRASH_COUNT=$MC_SERVER_CRASH_COUNT" 220 | echo "DEBUG: MC_SERVER_CRASH_TIMER=$MC_SERVER_CRASH_TIMER" 221 | echo "DEBUG: MC_SERVER_JAVA_PATH=$MC_SERVER_JAVA_PATH" 222 | echo "DEBUG: MC_SERVER_RUN_FROM_BAD_FOLDER=$MC_SERVER_RUN_FROM_BAD_FOLDER" 223 | echo "DEBUG: MC_SERVER_IGNORE_OFFLINE=$MC_SERVER_IGNORE_OFFLINE" 224 | echo "DEBUG: MC_SERVER_IGNORE_JAVA_CHECK=$MC_SERVER_IGNORE_JAVA_CHECK" 225 | echo "DEBUG: MC_SERVER_USE_SPONGE=$MC_SERVER_USE_SPONGE" 226 | echo "DEBUG: MC_SERVER_HIGH_CPU_PRIORITY=$MC_SERVER_HIGH_CPU_PRIORITY" 227 | echo "DEBUG: MC_SERVER_JMX_ENABLE=$MC_SERVER_JMX_ENABLE" 228 | echo "DEBUG: MC_SERVER_JMX_PORT=$MC_SERVER_JMX_PORT" 229 | echo "DEBUG: MC_SERVER_JMX_HOST=$MC_SERVER_JMX_HOST" 230 | echo "DEBUG: MC_SERVER_MODPACK_NAME=$MC_SERVER_MODPACK_NAME" 231 | echo "DEBUG: MC_SERVER_DEFAULT_WORLD_TYPE=$MC_SERVER_DEFAULT_WORLD_TYPE" 232 | echo "DEBUG: MC_SERVER_MCVER=$MC_SERVER_MCVER" 233 | echo "DEBUG: MC_SERVER_FORGEVER=$MC_SERVER_FORGEVER" 234 | echo "DEBUG: MC_SERVER_FORGESHORT=$MC_SERVER_FORGESHORT" 235 | echo "DEBUG: MC_SERVER_FORGEURL=$MC_SERVER_FORGEURL" 236 | echo "DEBUG: MC_SERVER_AUTO_RESPOND=$MC_SERVER_AUTO_RESPOND" 237 | echo "DEBUG: MC_SERVER_INSTALL_ONLY=$MC_SERVER_INSTALL_ONLY" 238 | echo "DEBUG: Basic System Info: $(uname -a)" 239 | 240 | if [[ $MC_SERVER_environment == "Mac" ]]; then 241 | echo "DEBUG: Total RAM estimate: $(sysctl hw.memsize | awk 'BEGIN {total = 1} {if (NR == 1 || NR == 3) total *=$NF} END {print total / 1024 / 1024" MB"}')" 242 | else 243 | echo "DEBUG: Total RAM estimate: $(getconf -a | grep PAGES | awk 'BEGIN {total = 1} {if (NR == 1 || NR == 3) total *=$NF} END {print total / 1024 / 1024" MB"}')" 244 | fi 245 | 246 | echo "DEBUG: Java Version info: " 247 | echo "DEBUG: Java path: $MC_SERVER_JAVA" 248 | $MC_SERVER_JAVA -version 249 | echo "DEBUG: Dumping current directory listing" 250 | ls -s1h 251 | }>>logs/serverstart.log 2>&1 252 | if [[ $MC_SERVER_INSTALL_ONLY == 1 ]]; then 253 | install_server 254 | exit 0 255 | fi 256 | 257 | #Asks the user if the want to force an install of the server 258 | if [[ $MC_SERVER_AUTO_RESPOND == 0 ]]; then 259 | export answer="n" 260 | read -r -t 6 -p "About to start server. Force re-install (y/n)? " answer 261 | if [[ "$answer" =~ ^([yY][eE][sS]|[yY])+$ ]]; then 262 | echo "INFO: User chose to manually re-install server files" >>logs/serverstart.log 2>&1 263 | echo "User chose to manually re-install server files" 264 | install_server 265 | fi 266 | fi 267 | 268 | # loop to restart server and check crash frequency 269 | a=0 270 | last_crash=$((SECONDS)) 271 | 272 | if [[ ${MC_SERVER_JMX_ENABLE} == 1 ]]; then 273 | echo "INFO: JMX Enabled on port ${MC_SERVER_JMX_PORT}" >>logs/serverstart.log 2>&1 274 | export MC_SERVER_ARGS="${MC_SERVER_JAVA_ARGS} -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=${MC_SERVER_JMX_PORT} -Dcom.sun.management.jmxremote.rmi.port=${MC_SERVER_JMX_PORT} -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=$MC_SERVER_JMX_HOST" 275 | else 276 | export MC_SERVER_ARGS=${MC_SERVER_JAVA_ARGS} 277 | fi 278 | 279 | run=true 280 | while $run ; do 281 | 282 | #Testing some stuff before the server starts 283 | 284 | #Checks if script is running in temp 285 | echo "DEBUG: Current directory is $(pwd)" >>logs/serverstart.log 286 | 287 | if [ "$(pwd)" = "/tmp" ] || [ "$(pwd)" = "/var/tmp" ]; then 288 | echo "Current directory appears to be TMP" 289 | echo "WARN: Current DIR is TEMP" >>logs/serverstart.log 290 | if [ ${MC_SERVER_RUN_FROM_BAD_FOLDER} -eq 0 ]; then 291 | echo "ERROR: Stopping due to bad folder (TMP)" >>logs/serverstart.log 292 | echo "RUN_FROM_BAD_FOLDER setting is off, exiting script" 293 | exit 0 294 | else 295 | echo "WARN: Bad folder (TMP) but continuing anyway" >>logs/serverstart.log 296 | echo "Bypassing cd=temp halt per script settings" 297 | fi 298 | fi 299 | 300 | #Checks if users has full read/write access to the server dir 301 | if [ ! -r . ] || [ ! -w . ]; then 302 | echo "WARN: Not full R/W access on current directory" 303 | echo "You do not have full R/W access to current directory" 304 | if [ ${MC_SERVER_RUN_FROM_BAD_FOLDER} -eq 0 ]; then 305 | echo "ERROR: Stopping due to bad folder (R/W access)" >>logs/serverstart.log 306 | echo "RUN_FROM_BAD_FOLDER setting is off, exiting script" 307 | exit 0 308 | else 309 | echo "WARN: Bad folder (R/W) cut continuing anyway" >>logs/serverstart.log 310 | echo "Bypassing no R/W halt (per script settings)" 311 | fi 312 | fi 313 | 314 | #Checks java version 315 | if [[ ${MC_SERVER_IGNORE_JAVA_CHECK} == 1 ]]; then 316 | echo "WARN: Skipping validation of proper Java install/version..". 317 | echo "IF Java is not installed, too old, or not 64-bit, the server probably won't start/run correctly" 318 | echo "WARN: Skipping validation of Java install..." >>logs/serverstart.log 319 | else 320 | command -v $MC_SERVER_JAVA >> /dev/null 2>&1 321 | if [ $? -eq 0 ]; then 322 | echo "DEBUG: Java found" >>logs/serverstart.log 323 | if [[ "$(${MC_SERVER_JAVA} -version 2>&1 | awk -F ' ' '/Bit/ {print $2}')" == "64-Bit" ]] || [[ "$(${MC_SERVER_JAVA} -version 2>&1 | awk -F ' ' '/Bit/ {print $3}')" == "64-Bit" ]]; then 324 | echo "DEBUG: 64-bit Java found" >>logs/serverstart.log 325 | else 326 | echo "ERROR: 64-bit Java not found" 327 | echo "ERROR: 64-bit Java not found" >>logs/serverstart.log 328 | exit 1 329 | fi 330 | if [ "$(${MC_SERVER_JAVA} -version 2>&1 | awk -F '"' '/version/ {print $2}' | cut -c1-3)" = "1.8" ]; then 331 | echo "DEBUG: Java 8 Found" >>logs/serverstart.log 332 | else 333 | echo "ERROR: Java 8 not found" 334 | echo "ERROR: Java 8 not found" >>logs/serverstart.log 335 | exit 1 336 | fi 337 | else 338 | echo "ERROR: Java is not installed install Java before continuing" 339 | echo "ERROR: No Java detected" >>logs/serverstart.log 340 | exit 1 341 | fi 342 | fi 343 | 344 | #Check internet connection 345 | if [ ${MC_SERVER_IGNORE_OFFLINE} -eq 1 ]; then 346 | echo "WARN: Internet connectivity checking is disabled" >>logs/serverstart.log 347 | echo "Skipping internet connectivity check" 348 | else 349 | command -v ping >> /dev/null 2>&1 350 | if [ $? -eq 0 ]; then 351 | echo "DEBUG: Ping found on system" >>logs/serverstart.log 352 | if ping -c 1 8.8.8.8 >> /dev/null 2>&1; then 353 | echo "INFO: Ping to Google DNS successful" >>logs/serverstart.log 354 | echo "Ping to Google DNS successful" 355 | else 356 | echo "ERROR: Ping to Google DNS failed. No internet access?" >>logs/serverstart.log 357 | echo "Ping to Google DNS failed. No internet access?" 358 | 359 | if ping -c 1 4.2.2.1 >> /dev/null 2>&1; then 360 | echo "INFO: Ping to L4 successful" >>logs/serverstart.log 361 | echo "Ping to L4 successful" 362 | else 363 | echo "ERROR: Ping to L4 failed. No internet access?" >>logs/serverstart.log 364 | echo "Ping to L4 failed. No internet access?" 365 | echo "IGNORE_OFFLINE is set to off exiting" 366 | exit 1 367 | fi 368 | fi 369 | else 370 | echo "WARN: Ping not install can not check network connection" >>logs/serverstart.log 371 | echo "Ping is not install can not assure internet connection" 372 | fi 373 | fi 374 | 375 | #Checking minecraft has the files its needs to run 376 | if [ ! -d ./libraries ] ; then 377 | echo "WARN: library directory not found" >>logs/serverstart.log 378 | echo "Required files not found, need to install Forge" 379 | install_server 380 | fi 381 | forge=$(ls forge*"$MC_SERVER_MCVER"*"$MC_SERVER_FORGEVER"*universal.jar 2>>logs/serverstart.log) 382 | if [[ $? != 0 ]] ; then 383 | echo "WARN: no forge jar for MCVER: $MC_SERVER_MCVER and FORGEVER: $MC_SERVER_FORGEVER found" >>logs/serverstart.log 384 | echo "Required files not found, need to install Forge" 385 | install_server 386 | else 387 | export MC_SERVER_FORGE_JAR="${forge[0]}" 388 | echo "DEBUG: Found forge jar: $MC_SERVER_FORGE_JAR" >>logs/serverstart.log 389 | fi 390 | 391 | if [ ! -f ./minecraft_server.${MC_SERVER_MCVER}.jar ] ; then 392 | echo "WARN: minecraft_server.${MC_SERVER_MCVER}.jar not found" >>logs/serverstart.log 393 | echo "Required files not found, need to install Forge" 394 | install_server 395 | fi 396 | 397 | #Checks if the EULA exists if not generates it 398 | if [ ! -f eula.txt ]; then 399 | echo "Could not find eula.txt going to generate it" 400 | eula_gen 401 | else 402 | if grep -Fxq "eula=true" eula.txt; then 403 | echo "INFO: Found 'eula=true' in 'eula.txt'" >>logs/serverstart.log 404 | else 405 | echo "Could not find 'eula=true' in 'eula.txt'" 406 | eula_gen 407 | fi 408 | fi 409 | 410 | #Checks if settings.properties exists and if not adds some default values 411 | if [ ! -f server.properties ]; then 412 | echo "Could not find server.properties, creating initial copy..." 413 | echo "INFO: server.properties not found... populating default" >>logs/serverstart.log 414 | { 415 | echo "view-distance=8" 416 | echo "allow-flight=true" 417 | echo "level-type=$MC_SERVER_DEFAULT_WORLD_TYPE" 418 | echo "snooper-enabled=false" 419 | echo "max-tick-time=90000" 420 | echo "motd=$MC_SERVER_MODPACK_NAME" 421 | }>> server.properties 422 | fi 423 | 424 | clear 425 | echo "Starting server" 426 | if [[ $MC_SERVER_JMX_ENABLE == 1 ]]; then 427 | echo "JMX Enabled on port ${MC_SERVER_JMX_PORT}" 428 | fi 429 | echo "INFO: Starting Server at $(date -u +%Y-%m-%d_%H:%M:%S)" >>logs/serverstart.log 2>&1 430 | "$MC_SERVER_JAVA" -Xmx"$MC_SERVER_MAX_RAM" "$MC_SERVER_ARGS" -jar "$MC_SERVER_FORGE_JAR" "$MC_SERVER_GAME_ARGS" 431 | b=$? 432 | b=1 433 | if [[ $b == 0 ]]; then 434 | echo "DEBUG: Server ended with code 0" >>logs/serverstart.log 435 | a=0 436 | else 437 | now=$((SECONDS)) 438 | diff=$now-$last_crash 439 | if [[ $diff -gt $MC_SERVER_CRASH_TIMER ]]; then 440 | a=1 441 | else 442 | a=$((a+1)) 443 | fi 444 | last_crash=$((SECONDS)) 445 | fi 446 | if [[ "$a" == "$MC_SERVER_CRASH_COUNT" ]]; then 447 | echo "The server has crashed too many times" 448 | echo "ERROR: Server has failed to start too many times in a row." >>logs/serverstart.log 449 | exit 1 450 | fi 451 | 452 | export answer="y" 453 | if [[ $MC_SERVER_AUTO_RESPOND == 0 ]]; then 454 | echo "Server will restart in ~10 seconds. No input needed..." 455 | read -r -t 12 -p "Restart now (y) or exit to shell (n)? " answer 456 | fi 457 | if [[ "$answer" =~ ^([nN][oO]|[nN])+$ ]]; then 458 | echo "INFO: User cancelled restart; exiting to shell" >>logs/serverstart.log 459 | echo "" 460 | exit 0 461 | fi 462 | echo "" 463 | echo "INFO: Server-auto-restart commencing" >>logs/serverstart.log 464 | echo "Rebooting now!" 465 | done 466 | -------------------------------------------------------------------------------- /settings.cfg: -------------------------------------------------------------------------------- 1 | ;SETTINGS FOR SERVERSTART SCRIPTS 2 | ;See "serverstart.log" in the LOGS subfolder 3 | ;For more details/help see: https://github.com/AllTheMods/Server-Scripts 4 | 5 | MAX_RAM=5G 6 | GAME_ARGS=nogui 7 | JAVA_ARGS=-d64 -server -XX:+AggressiveOpts -XX:ParallelGCThreads=3 -XX:+UseConcMarkSweepGC -XX:+UnlockExperimentalVMOptions -XX:+UseParNewGC -XX:+ExplicitGCInvokesConcurrent -XX:MaxGCPauseMillis=10 -XX:GCPauseIntervalMillis=50 -XX:+UseFastAccessorMethods -XX:+OptimizeStringConcat -XX:NewSize=84m -XX:+UseAdaptiveGCBoundary -XX:NewRatio=3 -Dfml.readTimeout=90 -Dfml.queryResult=confirm 8 | 9 | CRASH_COUNT=5 10 | CRASH_TIMER=600 11 | 12 | JAVA_PATH=DISABLE 13 | RUN_FROM_BAD_FOLDER=0 14 | IGNORE_OFFLINE=0 15 | IGNORE_JAVA_CHECK=0 16 | USE_SPONGE=0 17 | HIGH_CPU_PRIORITY=0 18 | 19 | JMX_ENABLE=0 20 | JMX_PORT=9010 21 | JMX_HOST=127.0.0.1 22 | 23 | MODPACK_NAME=All The Mods 3 Remix 24 | DEFAULT_WORLD_TYPE=BIOMESOP 25 | MCVER=1.12.2 26 | FORGEVER=14.23.5.2811 27 | FORGEURL=DISABLE 28 | --------------------------------------------------------------------------------