commit
8b54797eba
23
Dockerfile
Normal file
23
Dockerfile
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
FROM ubuntu:16.04
|
||||||
|
|
||||||
|
MAINTAINER Isaac A., <isaac@isaacs.site>
|
||||||
|
|
||||||
|
RUN apt update && \
|
||||||
|
apt upgrade -y && \
|
||||||
|
apt install -y lib32gcc1 lib32stdc++6 unzip curl && \
|
||||||
|
curl -sL https://deb.nodesource.com/setup_6.x | bash - && \
|
||||||
|
apt install -y nodejs && \
|
||||||
|
mkdir /node_modules && \
|
||||||
|
npm install --prefix / ws && \
|
||||||
|
useradd -d /home/container -m container
|
||||||
|
|
||||||
|
USER container
|
||||||
|
ENV USER container
|
||||||
|
ENV 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
|
# Rust
|
||||||
Generic docker containers designed to work with Pterodactyl Panel and its daemon.
|
|
||||||
|
|
|
||||||
25
entrypoint.sh
Normal file
25
entrypoint.sh
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
#!/bin/bash
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
cd /home/container
|
||||||
|
|
||||||
|
# Update Rust Server
|
||||||
|
./steam/steamcmd.sh +login anonymous +force_install_dir /home/container +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}"
|
||||||
|
|
||||||
|
if [ -f OXIDE_FLAG ]; then
|
||||||
|
echo "Updating OxideMod..."
|
||||||
|
curl -sSL "https://dl.bintray.com/oxidemod/builds/Oxide-Rust.zip" > oxide.zip
|
||||||
|
unzip -o -q oxide.zip
|
||||||
|
rm oxide.zip
|
||||||
|
echo "Done updating OxideMod!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Fix for Rust not starting
|
||||||
|
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(pwd)
|
||||||
|
|
||||||
|
# Run the Server
|
||||||
|
node /wrapper.js "${MODIFIED_STARTUP}"
|
||||||
85
wrapper.js
Normal file
85
wrapper.js
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
var startupCmd = "";
|
||||||
|
const fs = require("fs");
|
||||||
|
fs.writeFile("latest.log", "");
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
var exec = require("child_process").exec;
|
||||||
|
console.log("Starting Rust...");
|
||||||
|
exec(startupCmd);
|
||||||
|
|
||||||
|
var waiting = true;
|
||||||
|
|
||||||
|
var poll = function( ) {
|
||||||
|
function createPacket(command) {
|
||||||
|
var packet = {
|
||||||
|
Identifier: -1,
|
||||||
|
Message: command,
|
||||||
|
Name: "WebRcon"
|
||||||
|
};
|
||||||
|
return JSON.stringify(packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
var serverHostname = "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() {
|
||||||
|
waiting = false;
|
||||||
|
process.stdin.resume();
|
||||||
|
process.stdin.setEncoding("utf8");
|
||||||
|
var util = require("util");
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
} 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.");
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
poll();
|
||||||
Loading…
Reference in New Issue
Block a user