Compare commits
59 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fca03c292e | |||
| 3462040ad9 | |||
| 354f663603 | |||
| 2a8907b29a | |||
| 80144d49da | |||
| d79c62dbd2 | |||
| 4d1bc7c868 | |||
| 2d043b0372 | |||
|
|
b09850a772 | ||
|
|
3b845a7480 | ||
|
|
ec82494db4 | ||
|
|
ccce678a51 | ||
|
|
698b113646 | ||
|
|
49e28e6c1a | ||
|
|
1c59b3d862 | ||
|
|
ce52bd57c0 | ||
|
|
41388c0332 | ||
|
|
d8a6525381 | ||
|
|
224758d24a | ||
|
|
061f20e200 | ||
|
|
7b6869070a | ||
|
|
b971077432 | ||
|
|
d72405f642 | ||
|
|
bdc6b45f53 | ||
|
|
af2517a865 | ||
|
|
c9e65b2cbf | ||
|
|
6a20d5394c | ||
|
|
d3423aeb1b | ||
|
|
899a560f49 | ||
|
|
1865f4da7d | ||
|
|
d877ff283c | ||
|
|
155bc850b7 | ||
|
|
1e81a38ab4 | ||
|
|
9f7febc121 | ||
|
|
d7c6028e91 | ||
|
|
3866e16c9c | ||
|
|
5455f6a078 | ||
|
|
a1c29aa2e2 | ||
|
|
6e0f62258e | ||
|
|
a5830338b4 | ||
|
|
80cdbdc8de | ||
|
|
8a30b35c74 | ||
|
|
c70ace1cee | ||
|
|
6f9613743f | ||
|
|
bde1047915 | ||
|
|
cb1b20e8a5 | ||
|
|
fbeebd6e7b | ||
|
|
f74368500a | ||
|
|
52e1365df6 | ||
|
|
2290c4a68a | ||
|
|
07dfffcc4e | ||
|
|
4e55d20297 | ||
|
|
8b54797eba | ||
|
|
1bef2974d4 | ||
|
|
5961d67174 | ||
|
|
2e9c27f36a | ||
|
|
065be5e299 | ||
|
|
41e8bf3185 | ||
|
|
9874226646 |
21
Dockerfile
Normal file
21
Dockerfile
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
FROM debian:bullseye-slim
|
||||
|
||||
LABEL author="Makaren0" maintainer="Makaffe@hotmail.com"
|
||||
|
||||
RUN apt update \
|
||||
&& apt upgrade -y \
|
||||
&& dpkg --add-architecture i386; apt update -y; apt install -y curl wget file tar bzip2 gzip unzip bsdmainutils python3 util-linux ca-certificates binutils bc jq tmux netcat lib32gcc-s1 lib32stdc++6 lib32z1\
|
||||
&& apt install -y nodejs npm \
|
||||
&& mkdir /node_modules \
|
||||
&& npm install --prefix / ws \
|
||||
&& useradd -d /home/container -m container
|
||||
|
||||
USER container
|
||||
ENV USER=container HOME=/home/container
|
||||
|
||||
WORKDIR /home/container
|
||||
|
||||
COPY ./entrypoint.sh /entrypoint.sh
|
||||
COPY ./wrapper.js /wrapper.js
|
||||
|
||||
CMD ["/bin/bash", "/entrypoint.sh"]
|
||||
|
|
@ -1,2 +1 @@
|
|||
# Containers
|
||||
Generic docker containers designed to work with Pterodactyl Panel and its daemon.
|
||||
# Rust
|
||||
|
|
|
|||
27
entrypoint.sh
Normal file
27
entrypoint.sh
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#!/bin/bash
|
||||
cd /home/container
|
||||
|
||||
# Make internal Docker IP address available to processes.
|
||||
export INTERNAL_IP=`ip route get 1 | awk '{print $NF;exit}'`
|
||||
|
||||
# Update Rust Server
|
||||
./steamcmd/steamcmd.sh +force_install_dir /home/container +login anonymous +app_update 258550 +quit
|
||||
|
||||
# Replace Startup Variables
|
||||
MODIFIED_STARTUP=`eval echo $(echo ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')`
|
||||
echo ":/home/container$ ${MODIFIED_STARTUP}"
|
||||
|
||||
# OxideMod has been replaced with uMod
|
||||
if [ -f OXIDE_FLAG ] || [ "${OXIDE}" = 1 ] || [ "${UMOD}" = 1 ]; then
|
||||
echo "Updating uMod..."
|
||||
curl -sSL "https://github.com/OxideMod/Oxide.Rust/releases/latest/download/Oxide.Rust-linux.zip" > umod.zip
|
||||
unzip -o -q umod.zip
|
||||
rm umod.zip
|
||||
echo "Done updating uMod!"
|
||||
fi
|
||||
|
||||
# Fix for Rust not starting
|
||||
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(pwd)
|
||||
|
||||
# Run the Server
|
||||
node /wrapper.js "${MODIFIED_STARTUP}"
|
||||
139
wrapper.js
Normal file
139
wrapper.js
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
var startupCmd = "";
|
||||
const fs = require("fs");
|
||||
fs.writeFile("latest.log", "", (err) => {
|
||||
if (err) console.log("Callback error in appendFile:" + err);
|
||||
});
|
||||
|
||||
var args = process.argv.splice(process.execArgv.length + 2);
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
if (i === args.length - 1) {
|
||||
startupCmd += args[i];
|
||||
} else {
|
||||
startupCmd += args[i] + " ";
|
||||
}
|
||||
}
|
||||
|
||||
if (startupCmd.length < 1) {
|
||||
console.log("Error: Please specify a startup command.");
|
||||
process.exit();
|
||||
}
|
||||
|
||||
const seenPercentage = {};
|
||||
function filter(data) {
|
||||
const str = data.toString();
|
||||
if (str.startsWith("Loading Prefab Bundle ")) { // Rust seems to spam the same percentage, so filter out any duplicates.
|
||||
const percentage = str.substr("Loading Prefab Bundle ".length);
|
||||
if (seenPercentage[percentage]) return;
|
||||
|
||||
seenPercentage[percentage] = true;
|
||||
}
|
||||
|
||||
console.log(str);
|
||||
}
|
||||
|
||||
var exec = require("child_process").exec;
|
||||
console.log("Starting Rust...");
|
||||
|
||||
var exited = false;
|
||||
const gameProcess = exec(startupCmd);
|
||||
gameProcess.stdout.on('data', filter);
|
||||
gameProcess.stderr.on('data', filter);
|
||||
gameProcess.on('exit', function (code, signal) {
|
||||
exited = true;
|
||||
|
||||
if (code) {
|
||||
console.log("Main game process exited with code " + code);
|
||||
// process.exit(code);
|
||||
}
|
||||
});
|
||||
|
||||
function initialListener(data) {
|
||||
const command = data.toString().trim();
|
||||
if (command === 'quit') {
|
||||
gameProcess.kill('SIGTERM');
|
||||
} else {
|
||||
console.log('Unable to run "' + command + '" due to RCON not being connected yet.');
|
||||
}
|
||||
}
|
||||
process.stdin.resume();
|
||||
process.stdin.setEncoding("utf8");
|
||||
process.stdin.on('data', initialListener);
|
||||
|
||||
process.on('exit', function(code) {
|
||||
if (exited) return;
|
||||
|
||||
console.log("Received request to stop the process, stopping the game...");
|
||||
gameProcess.kill('SIGTERM');
|
||||
});
|
||||
|
||||
var waiting = true;
|
||||
var poll = function( ) {
|
||||
function createPacket(command) {
|
||||
var packet = {
|
||||
Identifier: -1,
|
||||
Message: command,
|
||||
Name: "WebRcon"
|
||||
};
|
||||
return JSON.stringify(packet);
|
||||
}
|
||||
|
||||
var serverHostname = process.env.RCON_IP ? process.env.RCON_IP : "localhost";
|
||||
var serverPort = process.env.RCON_PORT;
|
||||
var serverPassword = process.env.RCON_PASS;
|
||||
var WebSocket = require("ws");
|
||||
var ws = new WebSocket("ws://" + serverHostname + ":" + serverPort + "/" + serverPassword);
|
||||
|
||||
ws.on("open", function open() {
|
||||
console.log("Connected to RCON. Please wait until the server status switches to \"Running\".");
|
||||
waiting = false;
|
||||
|
||||
// Hack to fix broken console output
|
||||
ws.send(createPacket('status'));
|
||||
|
||||
process.stdin.removeListener('data', initialListener);
|
||||
gameProcess.stdout.removeListener('data', filter);
|
||||
gameProcess.stderr.removeListener('data', filter);
|
||||
process.stdin.on('data', function (text) {
|
||||
ws.send(createPacket(text));
|
||||
});
|
||||
});
|
||||
|
||||
ws.on("message", function(data, flags) {
|
||||
try {
|
||||
var json = JSON.parse(data);
|
||||
if (json !== undefined) {
|
||||
if (json.Message !== undefined && json.Message.length > 0) {
|
||||
console.log(json.Message);
|
||||
const fs = require("fs");
|
||||
fs.appendFile("latest.log", "\n" + json.Message, (err) => {
|
||||
if (err) console.log("Callback error in appendFile:"+err);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
console.log("Error: Invalid JSON received");
|
||||
}
|
||||
} catch (e) {
|
||||
if (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ws.on("error", function(err) {
|
||||
waiting = true;
|
||||
console.log("Waiting for RCON to come up...");
|
||||
setTimeout(poll, 5000);
|
||||
});
|
||||
|
||||
ws.on("close", function() {
|
||||
if (!waiting) {
|
||||
console.log("Connection to server closed.");
|
||||
|
||||
exited = true;
|
||||
process.exit();
|
||||
}
|
||||
});
|
||||
}
|
||||
poll();
|
||||
Loading…
Reference in New Issue
Block a user