first commit

This commit is contained in:
2024-12-06 05:52:08 -05:00
commit c03877d469
20 changed files with 688 additions and 0 deletions

View File

@ -0,0 +1,79 @@
FROM ubuntu:latest
# Update OS and install deps
RUN apt update && apt clean && apt upgrade -y
RUN apt install -y curl apt-utils sudo curl python3 python-is-python3 git wget nano openssh-server apt-transport-https zip
# Get JDK Ready
RUN wget -O - https://packages.adoptium.net/artifactory/api/gpg/key/public | sudo tee /usr/share/keyrings/adoptium.asc
RUN echo "deb [signed-by=/usr/share/keyrings/adoptium.asc] https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | sudo tee /etc/apt/sources.list.d/adoptium.list
RUN cat /etc/apt/sources.list.d/adoptium.list
RUN sudo apt-get update
RUN apt update
# Install memory safe JDK
RUN DEBIAN_FRONTEND=noninteractive apt install temurin-21-jdk -y
# Download fabric server
# This needs to be changed to the version you wish to support.
RUN mkdir -vp /home/mc
RUN mkdir -vp /home/mc/minecraft
#Auto Accept EULA for MC
COPY eula /home/mc/minecraft/eula.txt
COPY server.properties /home/mc/minecraft/server.properties
# Add a user
RUN useradd mc
# Let user use Bash
RUN usermod --shell /bin/bash mc
# Provide users ownership
RUN chown -R mc:mc /home/mc
#COPY mod manager installer
COPY mod-manager-installer.sh /var/mod-manager-installer.sh
RUN chmod +x /var/mod-manager-installer.sh
COPY connection_manager.js /usr/bin/connections
RUN chmod +x /usr/bin/connections
COPY connections.json /var/connections.json
RUN ln -s /usr/bin/connections /usr/bin/con
ENV PATH="/usr/bin:$PATH"
RUN apt-get install -y ca-certificates curl gnupg
RUN sudo mkdir -p /etc/apt/keyrings
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
ENV NODE_MAJOR=18
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
RUN apt-get update
RUN apt-get install nodejs -y
RUN npm install -g holesail
COPY pm2 /var/tools/pm2
COPY scripts /var/tools/scripts
COPY get_latest_fabric_version.js /var/tools/scripts
RUN cd /var/tools/scripts && npm i axios
RUN data=$(node /var/tools/scripts/get_latest_fabric_version.js 1.21.1) && \
echo "Download URL: $data" && \
wget -O /home/mc/minecraft/server.jar "$data"
RUN chmod +x -R /var/tools
# Install PM2
RUN npm install pm2 -g
# Copy over start.sh to allow for backround run
COPY start.sh /start.sh
RUN chmod +x /start.sh
# Set root pass
RUN echo 'root:noshallpass' | chpasswd
ENTRYPOINT ["/bin/bash", "/start.sh"]

View File

@ -0,0 +1,24 @@
#!/usr/bin/node
const { execSync } = require('child_process');
const port = 25565; // Fixed port
const connectionString = process.env.CONNECTION_STRING;
if (!connectionString) {
console.error("Error: CONNECTION_STRING environment variable is not set.");
process.exit(1);
}
console.log(`Starting connection with the following details:`);
console.log(`Port: ${port}`);
console.log(`Connection String: ${connectionString}`);
// Start the connection using PM2
const pm2cmd = `pm2 start holesail --name holesail_connection -- --live ${port} --connector "${connectionString}"`;
try {
execSync(pm2cmd, { stdio: 'inherit' });
console.log(`Connection started successfully on port ${port} using PM2.`);
} catch (err) {
console.error(`Error starting connection: ${err.message}`);
process.exit(1);
}

View File

3
mc-cluster-image/eula Normal file
View File

@ -0,0 +1,3 @@
#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://aka.ms/MinecraftEULA).
#Fri Jun 16 20:59:19 GMT 2023
eula=true

View File

@ -0,0 +1,48 @@
const axios = require('axios');
// Function to get the latest Fabric download URL
async function getLatestFabricDownloadURL(gameVersion) {
try {
// Fetch the loader versions for the given game version
const loaderResponse = await axios.get(`https://meta.fabricmc.net/v2/versions/loader/${gameVersion}`);
const loaderVersions = loaderResponse.data;
if (loaderVersions.length === 0) {
throw new Error('No loader versions found for this game version');
}
// Get the latest loader version details (assuming the first is the latest)
const latestLoader = loaderVersions[0].loader.version;
// Fetch the installer versions
const installerResponse = await axios.get('https://meta.fabricmc.net/v2/versions/installer');
const installerVersions = installerResponse.data;
if (installerVersions.length === 0) {
throw new Error('No installer versions found');
}
// Get the latest installer version (assuming the first is the latest)
const latestInstaller = installerVersions[0].version;
// Construct the download URL
const downloadURL = `https://meta.fabricmc.net/v2/versions/loader/${gameVersion}/${latestLoader}/${latestInstaller}/server/jar`;
console.log(downloadURL);
return downloadURL;
} catch (error) {
console.error('Error fetching Fabric versions:', error.message);
}
}
// Retrieve the game version from command line arguments
const gameVersion = process.argv[2];
// Check if game version is provided
if (!gameVersion) {
console.error('Please provide a game version as an argument');
process.exit(1);
}
// Call the function with the provided game version
getLatestFabricDownloadURL(gameVersion);

View File

@ -0,0 +1,91 @@
#!/bin/bash
MIN_NODE_VERSION=12
DOWNLOAD_DIR="/tmp/mod-manager-install"
INSTALL_DIR="/usr/local/lib/mod-manager"
BINARY_PATH="/usr/bin/mod-manager"
CYAN="\033[1;96m"
RED="\033[0;91m"
GREEN="\033[0;92m"
RESET='\033[0m'
print () {
echo -e "$1 $2 $RESET"
}
info () {
print "$CYAN" "$1"
}
error() {
print "$RED" "$1"
}
success() {
print "$GREEN" "$1"
}
if [ "$EUID" -ne 0 ]
then
error "This script must be ran as root. Please use sudo."
exit
fi
rm -rf "$DOWNLOAD_DIR" || exit
mkdir -p "$DOWNLOAD_DIR" || exit
# Verify compatible version of node is installed
info "Verifying node verison..."
NODE_VERSION_STR=$(node --version)
if [[ "$?" -eq 127 ]]
then
error "Node does not appear to be installed. Please install Node version $MIN_NODE_VERSION or higher"
exit
fi
npm --version
if [[ "$?" -eq 127 ]]
then
error "Npm does not appear to be installed. Please install npm and re run the installer"
exit
fi
NODE_VERSION=$( (echo $NODE_VERSION_STR | sed 's/\..*//') | sed "s/v//")
if [[ "$NODE_VERSION" -ge "$MIN_NODE_VERSION" ]]
then
success "A version of node greater than $MIN_NODE_VERSION is installed!"
else
error "A version of node greater than $MIN_NODE_VERSION is required. Please install it and re run this install script"
exit
fi
# Download source files
info "Downloading mod-manager source..."
git clone "https://git.ssh.surf/snxraven/mod-manager.git" "$DOWNLOAD_DIR" || exit
# Compile
info "Compiling..."
cd "$DOWNLOAD_DIR" || exit
npm install --save || exit
npm install -g @vercel/ncc || exit
npx tsc || exit
ncc build build/ts/mod-manager.js -o build/flat/ || exit
# Install
info "Installing..."
rm -rf "$INSTALL_DIR" || exit
mkdir -p "$INSTALL_DIR" || exit
cp -r build/flat/* "$INSTALL_DIR" || exit
# Creating executable
info "Creating executable..."
echo "node $INSTALL_DIR/index.js \$@" > $BINARY_PATH || exit
chmod +x $BINARY_PATH || exit
# Cleaning up
info "Cleaning up..."
rm -rf "$DOWNLOAD_DIR" || exit
success "Successfully installed mod-manager. Try mod-manager -h to learn more!"

View File

@ -0,0 +1,11 @@
{
"apps": [
{
"name": "MineCraft Server",
"cwd": "/home/mc/minecraft",
"script": "java -Xms1400M -Xmx4096M -jar server.jar --nogui",
"args": "",
"max_restarts": 5
}
]
}

View File

@ -0,0 +1,16 @@
#!/bin/bash
cd /home/mc/minecraft
flag_file="mod-manager.init"
if [ ! -f "$flag_file" ]; then
/var/mod-manager-installer.sh
echo "1.21.1" | mod-manager init
touch "$flag_file"
su - mc -c "pm2 restart all"
else
echo "Mod Manager is initialized already! Skipping..."
fi

View File

@ -0,0 +1,58 @@
#Minecraft server properties
#Fri Jun 16 21:24:32 GMT 2023
enable-jmx-monitoring=false
rcon.port=25575
level-seed=
gamemode=survival
enable-command-block=false
enable-query=false
generator-settings={}
enforce-secure-profile=false
level-name=world
motd=A Minecraft Server
query.port=25565
pvp=true
generate-structures=true
max-chained-neighbor-updates=1000000
difficulty=easy
network-compression-threshold=256
max-tick-time=60000
require-resource-pack=false
use-native-transport=true
max-players=20
online-mode=true
enable-status=true
allow-flight=false
initial-disabled-packs=
broadcast-rcon-to-ops=true
view-distance=10
server-ip=
resource-pack-prompt=
allow-nether=true
server-port=25565
enable-rcon=false
sync-chunk-writes=true
op-permission-level=4
prevent-proxy-connections=false
hide-online-players=false
resource-pack=
entity-broadcast-range-percentage=100
simulation-distance=10
rcon.password=
player-idle-timeout=0
force-gamemode=false
rate-limit=0
hardcore=false
white-list=false
broadcast-console-to-ops=true
spawn-npcs=true
spawn-animals=true
function-permission-level=2
initial-enabled-packs=vanilla
level-type=minecraft\:normal
text-filtering-config=
spawn-monsters=true
enforce-whitelist=false
spawn-protection=16
resource-pack-sha1=
max-world-size=29999984

20
mc-cluster-image/start.sh Normal file
View File

@ -0,0 +1,20 @@
#!/bin/sh
su - mc -c "cd /var/tools/pm2 && pm2 start startServer.json"
# Init mod manager in 15 seconds, allow server to generate first
sleep 15 && sh /var/tools/scripts/init-mod-manager.sh
cd /
# Run the specified commands
con
chmod 755 /home/mc
chown mc:mc /home/mc/* -R
chown mc:mc /home/mc/minecraft/.mod-manager
# get log
su - mc -c "pm2 log"
tail -f /dev/null