Skip to content

Commit

Permalink
Migrated to new web-based RCON system
Browse files Browse the repository at this point in the history
  • Loading branch information
Dids committed Apr 27, 2016
1 parent 9e17dac commit 78def23
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 54 deletions.
28 changes: 23 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:14.04
FROM ubuntu:16.04

MAINTAINER didstopia

Expand All @@ -11,8 +11,11 @@ RUN apt-get install -y \
software-properties-common \
python-software-properties \
lib32gcc1 \
libstdc++6 \
curl \
wget
wget \
bsdtar \
nginx

# Run as root
USER root
Expand All @@ -21,8 +24,19 @@ USER root
ENV TZ=Europe/Helsinki
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# Copy the block script
ADD block.sh /block.sh
# Remove default nginx stuff
RUN rm -fr /usr/share/nginx/html/* && \
rm -fr /etc/nginx/sites-available/* && \
rm -fr /etc/nginx/sites-enabled/*

# Install webrcon
COPY nginx_rcon.conf /etc/nginx/nginx.conf
RUN curl -sL https://github.com/Didstopia/webrcon/archive/gh-pages.zip | bsdtar -xvf- -C /tmp && \
mv /tmp/webrcon-gh-pages/* /usr/share/nginx/html/ && \
rm -fr /tmp/webrcon-gh-pages

# Customize the webrcon package to fit our needs
ADD fix_conn.sh /tmp/fix_conn.sh

# Create and set the steamcmd folder as a volume
RUN mkdir -p /steamcmd/rust
Expand All @@ -34,12 +48,14 @@ ADD install.txt /install.txt
# Copy the Rust startup script
ADD start_rust.sh /start.sh

# TODO: Rewrite to use the webrcon
# Setup RCON support
RUN apt-get install -y python-pip
RUN pip install python-valve
ADD shutdown.py /shutdown.py

# Expose necessary ports
EXPOSE 8080
EXPOSE 28015
EXPOSE 28016

Expand All @@ -49,8 +65,10 @@ ENV RUST_SERVER_NAME "Rust Server [DOCKER]"
ENV RUST_SERVER_DESCRIPTION "This is a Rust server running inside a Docker container!"
ENV RUST_SERVER_URL "https://hub.docker.com/r/didstopia/rust-server/"
ENV RUST_SERVER_BANNER_URL ""
ENV RUST_RCON_WEB "1"
ENV RUST_RCON_PORT "28016"
ENV RUST_RCON_PASSWORD ""
ENV RUST_RCON_PASSWORD "docker"
ENV RUST_RESPAWN_ON_RESTART "0"

# Start the server
ENTRYPOINT ["./start.sh"]
39 changes: 17 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
## Rust server that runs inside a Docker container
# Rust server that runs inside a Docker container

NOTE: This image will always install/update to the latest steamcmd and Rust server, all you have to do to update your server is to redeploy the container.
**WIP NOTE**: We're still testing the switch from the old RCON system to the new one, so until we can make sure that it's properly working, we'll keep this note here to remind you that it's still a work in progress.

Also note that the entire /steamcmd/rust can be mounted on the host system.
**NOTE**: This image will install/update on startup. The path ```/steamcmd/rust``` can be mounted on the host for data persistence.
Also note that this image provides the new web-based RCON, so you should set ```RUST_RCON_PASSWORD``` to a more secure password.

# How to run the server
1. Set the ```RUST_SERVER_STARTUP_ARGUMENTS``` environment variable to match your preferred server arguments (defaults are set to ```"-batchmode -load -logfile /dev/stdout +server.identity docker +server.seed 12345 +server.secure 1"```, note how we're logging to stdout)
1. Set the environment variables you wish to modify from below (note the RCON password!)
2. Optionally mount ```/steamcmd/rust``` somewhere on the host or inside another container to keep your data safe
3. Run the container and enjoy!
3. Enjoy!

The following environment variables are available and should be used individually instead of specifying them in the arguments variable:
The following environment variables are available:
```
RUST_SERVER_STARTUP_ARGUMENTS
RUST_SERVER_NAME
RUST_SERVER_DESCRIPTION
RUST_SERVER_URL
RUST_SERVER_BANNER_URL
RUST_RCON_PORT
RUST_RCON_PASSWORD
RUST_SERVER_STARTUP_ARGUMENTS (DEFAULT: "-batchmode -load -logfile /dev/stdout +server.identity docker +server.seed 12345 +server.secure 1")
RUST_SERVER_NAME (DEFAULT: "Rust Server [DOCKER]" - The publicly visible server name)
RUST_SERVER_DESCRIPTION (DEFAULT: "This is a Rust server running inside a Docker container!" - The publicly visible server description)
RUST_SERVER_URL (DEFAULT: "https://hub.docker.com/r/didstopia/rust-server/" - The publicly visible server website)
RUST_SERVER_BANNER_URL (DEFAULT: "" - The publicly visible server banner image URL)
RUST_RCON_WEB (DEFAULT "1" - Set to 1 or 0 to enable or disable the web-based RCON server)
RUST_RCON_PORT (DEFAULT: "28016" - RCON server port)
RUST_RCON_PASSWORD (DEFAULT: "docker" - RCON server password, please change this!)
RUST_RESPAWN_ON_RESTART (DEFAULT: "0" - Controls whether to respawn resources on startup)
```

IMPORTANT: You should set both the ```RUST_RCON_PORT``` and RUST_RCON_PASSWORD``` to enable RCON, which will also enable proper server shutdown when Docker sends the shutdown/kill command. It essentially connects to the RCON server and executed the ```quit``` command, which properly shuts down the server.



You can also set the following variables to **"true"** if you want to block a specific service:
```
RUST_SERVER_BLOCK_RUSTIO
```
*Please note that the blocking feature has not been thoroughly tested yet (ie. probably doesn't even work yet) and is constantly being worked on.*
If you need help, have questions or bug submissions, feel free to contact me **@Dids** on Twitter, and on the *Rust Server Owners* Slack community.
23 changes: 0 additions & 23 deletions block.sh

This file was deleted.

2 changes: 1 addition & 1 deletion docker_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
eval "$(docker-machine env default)"

# Run the server
docker run -v $(pwd)/rust_data:/steamcmd/rust -e RUST_RCON_PORT="28016" -e RUST_RCON_PASSWORD="docker" -e RUST_SERVER_BLOCK_RUSTIO="true" -e RUST_SERVER_BLOCK_PLAYRUSTHQ="true" --name rust-server -d didstopia/rust-server:latest
docker run -p 28015:28015 -p 28016:28016 -p 80:8080 -v $(pwd)/rust_data:/steamcmd/rust -e RUST_RESPAWN_ON_RESTART=1 --name rust-server -d didstopia/rust-server:latest
docker logs -f rust-server
18 changes: 18 additions & 0 deletions fix_conn.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# $scope.Address = $scope.Address.trim();

# Replace the trimmed address field with the current domain/hostname and RCON port
OLD_TRIM_CODE='scope.Address = $scope.Address.trim();'
NEW_ADDRESS_CODE='scope.Address = $location.host() + '"\":$RUST_RCON_PORT\";"
sed -i -e 's/'"$OLD_TRIM_CODE"'/'"$NEW_ADDRESS_CODE"'/g' /usr/share/nginx/html/js/connection.js

# Replace the help text with our own
OLD_HELP_TEXT="Enter the address (including rcon port) and the rcon password below to connect."
NEW_HELP_TEXT="Enter the rcon password below to connect."
sed -i -e 's/'"$OLD_HELP_TEXT"'/'"$NEW_HELP_TEXT"'/g' /usr/share/nginx/html/html/connect.html

# Remove the address lines (14-19) if they exist
if grep -q "ng-model=\"Address\"" /usr/share/nginx/html/html/connect.html; then
sed -i -e '14,19d' /usr/share/nginx/html/html/connect.html
fi
32 changes: 32 additions & 0 deletions nginx_rcon.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
worker_processes 1;
error_log /tmp/nginx_error.log;
pid /tmp/nginx.pid;

events
{
worker_connections 128;
}

http
{
client_body_temp_path /tmp/client_body;
fastcgi_temp_path /tmp/fastcgi_temp;
proxy_temp_path /tmp/proxy_temp;
scgi_temp_path /tmp/scgi_temp;
uwsgi_temp_path /tmp/uwsgi_temp;
include /etc/nginx/mime.types;
default_type application/octet-stream;

server
{
listen 8080;
server_name localhost;
location /
{
root /usr/share/nginx/html;
index index.html index.htm;
error_log /tmp/nginx_error.log;
access_log /tmp/nginx_access.log;
}
}
}
2 changes: 2 additions & 0 deletions shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
SERVER_ADDRESS = ("localhost", int(os.environ.get('RUST_RCON_PORT')))
PASSWORD = os.environ.get('RUST_RCON_PASSWORD')

# TODO: Rewrite to use websocket based rcon instead

try:
with RCON(SERVER_ADDRESS, PASSWORD, 5) as rcon:
rcon("quit")
Expand Down
21 changes: 18 additions & 3 deletions start_rust.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ if [ ! -d "/steamcmd/rust" ]; then
mkdir -p /steamcmd/rust
fi

# Check if we need to block a service
bash /block.sh

# Install/update steamcmd
echo "Installing/updating steamcmd.."
curl -s http://media.steampowered.com/installer/steamcmd_linux.tar.gz | tar -v -C /steamcmd -zx
Expand All @@ -37,6 +34,24 @@ fi
if [ ! -z ${RUST_RCON_PASSWORD+x} ]; then
RUST_STARTUP_COMMAND="$RUST_STARTUP_COMMAND +rcon.password $RUST_RCON_PASSWORD"
fi
if [ ! -z ${RUST_RESPAWN_ON_RESTART+x} ]; then
if [ "$RUST_RESPAWN_ON_RESTART" = "1" ]; then
RUST_STARTUP_COMMAND="$RUST_STARTUP_COMMAND +spawn.fill_groups"
fi
fi

if [ ! -z ${RUST_RCON_WEB+x} ]; then
RUST_STARTUP_COMMAND="$RUST_STARTUP_COMMAND +rcon.web $RUST_RCON_WEB"
if [ "$RUST_RCON_WEB" = "1" ]; then
# Fix the webrcon (customize a few elements)
bash /tmp/fix_conn.sh

# Start nginx (in the background)
echo "Starting web server.."
nginx && sleep 5
#nginx -g "daemon off;" && sleep 5
fi
fi

# Set the working directory
cd /steamcmd/rust
Expand Down

0 comments on commit 78def23

Please sign in to comment.