Add Rust container
This commit is contained in:
parent
6a4392992f
commit
9874226646
22
Dockerfile
Normal file
22
Dockerfile
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
FROM ubuntu:16.04
|
||||
|
||||
MAINTAINER Isaac A., <isaac@isaacs.site>
|
||||
|
||||
RUN apt update && \
|
||||
apt upgrade -y && \
|
||||
apt install -y lib32gcc1 lib32stdc++6 curl && \
|
||||
curl -sL https://deb.nodesource.com/setup_6.x | bash - && \
|
||||
apt install -y nodejs && \
|
||||
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
|
||||
COPY ./node_modules/ /node_modules/
|
||||
|
||||
CMD ["/bin/bash", "/entrypoint.sh"]
|
||||
|
|
@ -1,2 +1 @@
|
|||
# Containers
|
||||
Generic docker containers designed to work with Pterodactyl Panel and its daemon.
|
||||
# Rust
|
||||
|
|
|
|||
14
entrypoint.sh
Normal file
14
entrypoint.sh
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#!/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}"
|
||||
|
||||
# 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