Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement: Combine start and download scripts. Improve and expand file-checks. #81

Closed
kreezxil opened this issue Sep 30, 2021 · 19 comments
Assignees
Labels
accepted Feature Ask which got accepted. enhancement New feature, request or improvement

Comments

@kreezxil
Copy link
Sponsor

  • What is the current behavior?

When the pack is created there are two scripts. one to start the forge and another to download minecraft server jar.

  • What is the wanted/requested behavior?

Use only start-forge and if the minecraft server jar is missing, then the batch coded needed to retrieve it is run.

  • What are your reasons for making this feature request? Provide solid arguments on why I should start working on it.
    Someone requested it on my discord. I've also had code like this before in my own scripts.

For example this is my script to download and install forge server which in it's own function will down the minecraft server jar.

#!/bin/bash

# used for renaming the forge jar to the name of the current folder.
FORGE="${PWD##*/}.jar" 
TIER="1.12.2"
PATTERN="${TIER}-14.23.5.${1}"
INSTALLER="https://files.minecraftforge.net/maven/net/minecraftforge/forge/${PATTERN}/forge-${PATTERN}-installer.jar"

echo "${INSTALLER}" > CURRENT_INSTALLER

FORGE_INSTALLER=$(basename "${INSTALLER}")

wget "${INSTALLER}"

java -jar "${FORGE_INSTALLER}" --installServer

rm "${FORGE_INSTALLER}"

mv -v forge*jar "${FORGE}"

I have settings.sh file that contains the following, so that the script after will make sense:

#just to set some globals used by the other scripts
USER="$(whoami)"
FORGE="${PWD##*/}.jar"
THISPATH="$(pwd)"
read INSTALLER < CURRENT_INSTALLER

OPTIONS='nogui'
USERNAME="${USER}"
WORLD='world'
MCPATH="${THISPATH}"
SESSION_NAME="$(basename ${THISPATH})"

# The following is used for SCREEN scroll back.
# It is not used in Windows
HISTORY=1024

# HEAP is JAVA saying MEMORY or RAM 
# valid values are a number followed by
# a letter. M = megabyte, G = gigabyte
# it is recommend to keep both values equal
# to help minimize garbage collection thrashing

MINHEAP=4G
MAXHEAP=6G


# Adjust the following based on your machine's
# capability
MAXPERMSIZE=256M
THREADSTACK=512M

# the one setting if you specify more cores or
# threads than you have it will simply use all
# of your cores/threads.
CPU_COUNT=4

My main start forge wrapper that I actually use, yours is good for testing tho.

#!/bin/bash
source settings.sh

#the following if block performs dark magic
#to install forge if it is not installed

if [ ! -e "${FORGE}" ]; then
   wget "${INSTALLER}"
   java -jar "${INSTALLER}" --installServer
   mv *universal.jar "${FORGE}"
fi
 
 OPTIONS='nogui'
 HEAP="${MAXHEAP}"

 INVOCATION="java \
 -Xms${HEAP} -Xmx${HEAP} \
 -Dfml.debugClassPatchManager=true -Dfml.debugRegistryEntries=true \
 -Djava.net.preferIPv4Stack=true \
 -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+UseParNewGC \
 -XX:+UseNUMA -XX:+CMSParallelRemarkEnabled -XX:MaxTenuringThreshold=15 \
 -XX:MaxGCPauseMillis=30 -XX:GCPauseIntervalMillis=150 \
 -XX:+UseAdaptiveGCBoundary -XX:-UseGCOverheadLimit -XX:+UseBiasedLocking \
 -XX:SurvivorRatio=8 -XX:TargetSurvivorRatio=90 -XX:MaxTenuringThreshold=15 \
 -Dfml.ignorePatchDiscrepancies=true \
 -Dfml.ignoreInvalidMinecraftCertificates=true -XX:+UseFastAccessorMethods \
 -XX:+UseCompressedOops -XX:+OptimizeStringConcat -XX:+AggressiveOpts \
 -XX:ReservedCodeCacheSize=2048m -XX:+UseCodeCacheFlushing \
 -XX:SoftRefLRUPolicyMSPerMB=10000 -XX:ParallelGCThreads=2 \
 -Dfml.queryResult=confirm -Dfml.doNotBackup=true \
 -jar ${FORGE} $OPTIONS"

while true
do
	screen -S "${SESSION_NAME}_SERVER" ${INVOCATION}
	echo "If you want to completely stop the server restart process now, press Ctrl+C before the time is up!"
	echo "Rebooting in:"
	for i in 5 4 3 2 1
	do
		echo "$i..."
		sleep 1
	done
	echo "Rebooting now!"
done

So this last one, if the forge jar is missing, it will install the server so that it won't be missing. This is also why I renamed the forge server.jar to the name of the current folder, so I don't have to edit this wrapper all the time.

I'm not sure how to do this in MS DOS batch, but it can be done relatively easily in PowerShell. Which is what every Windows user should be using now.

@Griefed Griefed self-assigned this Oct 1, 2021
@Griefed Griefed added the enhancement New feature, request or improvement label Oct 1, 2021
@Griefed Griefed added this to To do in Issue Tracker via automation Oct 1, 2021
@kreezxil
Copy link
Sponsor Author

kreezxil commented Oct 1, 2021

This works as expected.

It's a marriage of dos and PowerShell, which is what you're clearly doing.

IF NOT EXIST minecraft_server.1.16.5.jar powershell -Command "(New-Object Net.WebClient).DownloadFile('https://launcher.mojang.com/v1/objects/1b557e7b033b583cd9f66746b7a9ab1ec1673ced/server.jar', 'minecraft_server.1.16.5.jar')"

Meaning, you can slide it right into the top of your start-forge.bat script. And the other thing I provided for the start-forge.sh.

@kreezxil
Copy link
Sponsor Author

kreezxil commented Oct 1, 2021

So, update start-forge.sh script would look like this:

if [ ! -e "minecraft_server.1.16.5.jar" ]; then
  wget -O minecraft_server.1.16.5.jar https://launcher.mojang.com/v1/objects/1b557e7b033b583cd9f66746b7a9ab1ec1673ced/server.jar
fi

java -Xmx8G -Xms8G -jar forge.jar --nogui

and the updated start-forge.bat like this:

IF NOT EXIST minecraft_server.1.16.5.jar powershell -Command "(New-Object Net.WebClient).DownloadFile('https://launcher.mojang.com/v1/objects/1b557e7b033b583cd9f66746b7a9ab1ec1673ced/server.jar', 'minecraft_server.1.16.5.jar')"

java -Xmx8G -Xms8G -jar forge.jar --nogui

pause

@Griefed
Copy link
Owner

Griefed commented Oct 1, 2021

Heya Kreezxil,

thanks for putting in so much work on this issue! I'm definitely going to take a closer look at this. Currently busy with #80 🙂

I'll let you know when I start working on this.

Cheers,
Griefed

@kreezxil
Copy link
Sponsor Author

kreezxil commented Oct 1, 2021

Yep.

Might as well check for the existence of eula.txt too and if it doesn't exist create a file with one line

eula=true

Right before running the server.

Basically, what the Minecraft server hosting companies do.

=== Thus ===

Linux (start-forge.sh)

if [ ! -e "minecraft_server.1.16.5.jar" ]; then
  wget -O minecraft_server.1.16.5.jar https://launcher.mojang.com/v1/objects/1b557e7b033b583cd9f66746b7a9ab1ec1673ced/server.jar
fi

if [ ! -e "eula.txt" ]; then
  echo "eula=true" > eula.txt
fi

java -Xmx8G -Xms8G -jar forge.jar --nogui

Dos/PS (start-forge.bat)

IF NOT EXIST minecraft_server.1.16.5.jar powershell -Command "(New-Object Net.WebClient).DownloadFile('https://launcher.mojang.com/v1/objects/1b557e7b033b583cd9f66746b7a9ab1ec1673ced/server.jar', 'minecraft_server.1.16.5.jar')"

IF NOT EXIST eula.txt echo "eula=true" > eula.txt

java -Xmx8G -Xms8G -jar forge.jar --nogui

pause

@kreezxil
Copy link
Sponsor Author

kreezxil commented Oct 1, 2021

Right, that's all I can think of, implementing these on my side manually on each new server pack release.

@Griefed
Copy link
Owner

Griefed commented Oct 1, 2021

Might also be a good idea to add a check for the forge/fabric jars, so if a user does not let ServerPackCreator install the server, the script can handle that, too.

@kreezxil
Copy link
Sponsor Author

kreezxil commented Oct 2, 2021 via email

@Griefed
Copy link
Owner

Griefed commented Oct 4, 2021

So, for the bash-script for Forge I've now got this:

#!/usr/bin/env bash
# Start script generated by ServerPackCreator.
# This script checks for the Minecraft and Forge JAR-files, and if they are not found, they are downloaded.
# If everything is in order, the server is started.

MINECRAFT="1.16.5"
FORGE="36.2.4"
SERVER="1b557e7b033b583cd9f66746b7a9ab1ec1673ced"
ARGS="-Xmx8192M -Xms1024M -XX:+UseG1GC -Dsun.rmi.dgc.server.gcInterval=2147483646 -XX:+UnlockExperimentalVMOptions -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=51 -XX:G1HeapRegionSize=32M -XX:InitiatingHeapOccupancyPercent=10 -XX:G1MixedGCLiveThresholdPercent=50"

if [[ ! -s "forge.jar" ]];then

  echo "Forge Server JAR-file not found. Downloading installer...";
  wget -O forge-installer.jar https://files.minecraftforge.net/maven/net/minecraftforge/forge/$MINECRAFT-$FORGE/forge-$MINECRAFT-$FORGE-installer.jar;

  if [[ -s "forge-installer.jar" ]]; then

    echo "Installer downloaded. Installing...";
    java -jar forge-installer.jar --installServer;
    mv forge-$MINECRAFT-$FORGE.jar forge.jar;

    if [[ -s "forge.jar" ]];then
      rm -f forge-installer.jar;
      echo "Installation complete. forge-installer.jar deleted.";
    fi

  else
    echo "forge-installer.jar not found. Maybe the Forges servers are having trouble.";
    echo "Please try again in a couple of minutes.";
  fi
else
  echo "forge.jar present. Moving on..."
fi

if [[ ! -s "minecraft_server.$MINECRAFT.jar" ]];then
  echo "Minecraft Server JAR-file not found. Downloading...";
  wget -O minecraft_server.$MINECRAFT.jar https://launcher.mojang.com/v1/objects/$SERVER/server.jar;
else
  echo "minecraft_server.$MINECRAFT.jar present. Moving on..."
fi

if [[ ! -s "eula.txt" ]];then
  echo "eula.txt not found. Creating...";
  echo "#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://account.mojang.com/documents/minecraft_eula)." > eula.txt;
  echo "eula=true" >> eula.txt;
else
  echo "eula.txt present. Moving on...";
fi

echo "Starting server...";
echo "Minecraft version: $MINECRAFT";
echo "Forge version: $FORGE";
echo "Java args: $ARGS";

java $ARGS -jar forge.jar --nogui

-sbecause it also checks whether the file is greater than zero.

Now for the batch/ps script.

@Griefed
Copy link
Owner

Griefed commented Oct 4, 2021

Batch script for Forge:

:: Start script generated by ServerPackCreator.
:: This script checks for the Minecraft and Forge JAR-files, and if they are not found, they are downloaded.
:: If everything is in order, the server is started.
@ECHO off

SET MINECRAFT="1.16.5"
SET FORGE="36.2.4"
SET SERVER="1b557e7b033b583cd9f66746b7a9ab1ec1673ced"
SET ARGS=-Xmx8192M -Xms1024M -XX:+UseG1GC -Dsun.rmi.dgc.server.gcInterval=2147483646 -XX:+UnlockExperimentalVMOptions -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=51 -XX:G1HeapRegionSize=32M -XX:InitiatingHeapOccupancyPercent=10 -XX:G1MixedGCLiveThresholdPercent=50

IF NOT EXIST forge.jar (

  ECHO "Forge Server JAR-file not found. Downloading installer..."
  powershell -Command "(New-Object Net.WebClient).DownloadFile('https://files.minecraftforge.net/maven/net/minecraftforge/forge/%MINECRAFT%-%FORGE%/forge-%MINECRAFT%-%FORGE%-installer.jar', 'forge-installer.jar')"

  IF EXIST forge-installer.jar (

    ECHO "Installer downloaded. Installing..."
    java -jar forge-installer.jar --installServer
    MOVE forge-%MINECRAFT%-%FORGE%.jar forge.jar

    IF EXIST forge.jar (
      DEL forge-installer.jar
      ECHO "Installation complete. forge-installer.jar deleted."
    )

  ) ELSE (
    ECHO "forge-installer.jar not found. Maybe the Forges servers are having trouble."
    ECHO "Please try again in a couple of minutes."
  )
) ELSE (
  ECHO "forge.jar present. Moving on..."
)

IF NOT EXIST minecraft_server.%MINECRAFT%.jar (
  ECHO "Minecraft Server JAR-file not found. Downloading..."
  powershell -Command "(New-Object Net.WebClient).DownloadFile('https://launcher.mojang.com/v1/objects/%SERVER%/server.jar', 'minecraft_server.%MINECRAFT%.jar')"
) ELSE (
  ECHO "minecraft_server.%MINECRAFT%.jar present. Moving on..."
)

IF NOT EXIST eula.txt (
  ECHO "eula.txt not found. Creating..."
  ECHO #By changing the setting below to TRUE you are indicating your agreement to our EULA ^(https://account.mojang.com/documents/minecraft_eula^).> eula.txt
  ECHO eula=true>> eula.txt
) ELSE (
  ECHO "eula.txt present. Moving on..."
)

ECHO "Starting server..."
ECHO "Minecraft version: %MINECRAFT%"
ECHO "Forge version: %FORGE%"
ECHO "Java args: %ARGS%"

java %ARGS% -jar forge.jar --nogui

PAUSE

@Griefed
Copy link
Owner

Griefed commented Oct 4, 2021

Needless to say the Java args will be set by ServerPackCreator. That's just a placeholder, much like the download links, Minecraft and Forge versions.

@kreezxil
Copy link
Sponsor Author

kreezxil commented Oct 5, 2021

Looking good, EPIC attribute has increased by 10

@Griefed Griefed changed the title combine the scripts. Feature: Combine start and download scripts. Improve and expand file-checks. Oct 5, 2021
@Griefed
Copy link
Owner

Griefed commented Oct 5, 2021

That's the Forge Windows and Linux script templates pretty much done.
Now we're just missing the Fabric Windows and Linux templates and finally the implementation of these new scripts in ServerPackCreator.

Also, question: Since we are combining the scripts, thus replacing the download scripts. it would make sense to remove the option "Generate start-scripts" and have ServerPackCreator always generate said scripts for every server pack.
Otherwise we run into the issue of people not knowing how to get their Minecraft server-jar when they downloaded a server pack zip-archive generated by ServerPackCreator.
Thoughts?

@kreezxil
Copy link
Sponsor Author

kreezxil commented Oct 6, 2021 via email

@Griefed Griefed changed the title Feature: Combine start and download scripts. Improve and expand file-checks. Improvement: Combine start and download scripts. Improve and expand file-checks. Oct 9, 2021
@Griefed Griefed added the Working on it Indicates that work is being done on this issue/pr label Oct 10, 2021
@Griefed
Copy link
Owner

Griefed commented Oct 10, 2021

Fabric batch script:

:: Start script generated by ServerPackCreator.
:: This script checks for the Minecraft and Fabric JAR-files, and if they are not found, they are downloaded.
:: If everything is in order, the server is started.
@ECHO off

SET MINECRAFT="1.16.5"
SET FABRIC="0.12.1"
SET INSTALLER="0.8.0"
SET SERVER="1b557e7b033b583cd9f66746b7a9ab1ec1673ced"
SET ARGS=-Xmx8192M -Xms1024M -XX:+UseG1GC -Dsun.rmi.dgc.server.gcInterval=2147483646 -XX:+UnlockExperimentalVMOptions -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=51 -XX:G1HeapRegionSize=32M -XX:InitiatingHeapOccupancyPercent=10 -XX:G1MixedGCLiveThresholdPercent=50

IF NOT EXIST fabric-server-launch.jar (

  ECHO "Fabric Server JAR-file not found. Downloading installer..."
  powershell -Command "(New-Object Net.WebClient).DownloadFile('https://maven.fabricmc.net/net/fabricmc/fabric-installer/%INSTALLER%/fabric-installer-%INSTALLER%.jar', 'fabric-installer.jar')"

  IF EXIST fabric-installer.jar (

    ECHO "Installer downloaded. Installing..."
    java -jar fabric-installer.jar server -mcversion %MINECRAFT% -loader %FABRIC% -downloadMinecraft

    IF EXIST fabric-server-launch.jar (
      RMDIR /S /Q .fabric-installer
      DEL fabric-installer.jar
      ECHO "Installation complete. fabric-installer.jar and installation files deleted."
    )

  ) ELSE (
    ECHO "fabric-installer.jar not found. Maybe the Fabric servers are having trouble."
    ECHO "Please try again in a couple of minutes."
  )
) ELSE (
  ECHO "fabric-server-launch.jar present. Moving on..."
)

IF NOT EXIST server.jar (
  ECHO "Minecraft Server JAR-file not found. Downloading..."
  powershell -Command "(New-Object Net.WebClient).DownloadFile('https://launcher.mojang.com/v1/objects/%SERVER%/server.jar', 'server.jar')"
) ELSE (
  ECHO "server.jar present. Moving on..."
)

IF NOT EXIST eula.txt (
  ECHO "eula.txt not found. Creating..."
  ECHO #By changing the setting below to TRUE you are indicating your agreement to our EULA ^(https://account.mojang.com/documents/minecraft_eula^).> eula.txt
  ECHO eula=true>> eula.txt
) ELSE (
  ECHO "eula.txt present. Moving on..."
)

ECHO "Starting server..."
ECHO "Minecraft version: %MINECRAFT%"
ECHO "Fabric version: %FABRIC%"
ECHO "Java args: %ARGS%"

java %ARGS% -jar fabric-server-launch.jar --nogui

PAUSE

@Griefed
Copy link
Owner

Griefed commented Oct 10, 2021

Fabric shell:

#!/usr/bin/env bash
# Start script generated by ServerPackCreator.
# This script checks for the Miencraft and Forge JAR-Files, and if they are not found, they are downloaded.
# If everything is in order, the server is started.

MINECRAFT="1.16.5"
FABRIC="0.12.1"
INSTALLER="0.8.0"
SERVER="1b557e7b033b583cd9f66746b7a9ab1ec1673ced"
ARGS="-Xmx8192M -Xms1024M -XX:+UseG1GC -Dsun.rmi.dgc.server.gcInterval=2147483646 -XX:+UnlockExperimentalVMOptions -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMil>

if [[ ! -s "fabric-server-launch.jar" ]];then

  echo "Fabric Server JAR-file not found. Downloading installer...";
  wget -O fabric-installer.jar https://maven.fabricmc.net/net/fabricmc/fabric-installer/$INSTALLER/fabric-installer-$INSTALLER.jar;

  if [[ -s "fabric-installer.jar" ]];then

    echo "Installer downloaded. Installing...";
    java -jar fabric-installer.jar server -mcversion $MINECRAFT -loader $FABRIC -downloadMinecraft;

    if [[ -s "fabric-server-launch.jar" ]];then
      rm -rf .fabric-installer;
      rm -f fabric-installer.jar;
      echo "Installation complete. fabric-installer.jar deleted.";
    fi

  else
    echo "fabric-installer.jar not found. Maybe the Fabric server are having trouble.";
    echo "Please try again in a couple of minutes.";
  fi
else
  echo "fabric-server-launch.jar present. Moving on...";
fi

if [[ ! -s "server.jar" ]];then
  echo "Minecraft Server JAR-file not found. Downloading...";
  wget -O server.jar https://launcher.mojang.com/v1/objects/$SERVER/server.jar;
else
  echo "server.jar present. Moving on...";
fi

if [[ ! -s "eula.txt" ]];then
  echo "eula.txt not found. Creating...";
  echo "#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://account.mojang.com/documents/minecraft_eula)." > eula.txt;
  echo "eula=true" >> eula.txt;
else
  echo "eula.txt present. Moving on...";
fi

echo "Starting server...";
echo "Minecraft version: $MINECRAFT";
echo "Fabric version: $FABRIC";
echo "Java args: $ARGS";

java $ARGS -jar fabric-server-launch.jar --nogui

@kreezxil
Copy link
Sponsor Author

kreezxil commented Oct 10, 2021 via email

Griefed added a commit that referenced this issue Oct 10, 2021
… scripts. Removes option to generate scripts and generates them always instead. Closes issue #81
@Griefed
Copy link
Owner

Griefed commented Oct 10, 2021

Will be available in the next alpha release (or from the test pipeline if you so desire). scripts will no longer be called start-<modloader>.bat|sh but rather start.bat|sh instead, now.

@kreezxil
Copy link
Sponsor Author

kreezxil commented Oct 10, 2021 via email

@Griefed Griefed removed the Working on it Indicates that work is being done on this issue/pr label Oct 10, 2021
@Griefed
Copy link
Owner

Griefed commented Oct 11, 2021

See alpha.7

@Griefed Griefed closed this as completed Oct 11, 2021
Issue Tracker automation moved this from To do to Done Oct 11, 2021
@Griefed Griefed added the accepted Feature Ask which got accepted. label Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Feature Ask which got accepted. enhancement New feature, request or improvement
Projects
No open projects
Issue Tracker
  
Done
Development

No branches or pull requests

2 participants