diff --git a/7dtd-server.run b/7dtd-server.run deleted file mode 100755 index 210497a..0000000 --- a/7dtd-server.run +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -if [ ! -d /tmp/livingdead ]; then - mkdir /tmp/livingdead -fi - -docker run --net="host" -d -p 8080:8080 -p 8081:8081 -p 26900:26900 -p 26901:26901 -p 26902:26902 --name="7dtd" 7dtd diff --git a/7dtd.sh b/7dtd.sh index 3e8b71b..4665755 100755 --- a/7dtd.sh +++ b/7dtd.sh @@ -1,26 +1,33 @@ #!/bin/bash set -e -PARAMS=$@ -LIVINGDEAD_HOME=/home/livingdead +# This script manages the 7 days to Die server. +# $DATA_HOME and $STEAM_HOME are set in Dockerfile -cd $LIVINGDEAD_HOME +PARAMS="$@" -echo "Downloading Steam Cmd" -su -l livingdead -c "wget http://media.steampowered.com/installer/steamcmd_linux.tar.gz -O steamcmd_linux.tar.gz" -su -l livingdead -c "tar -zxf steamcmd_linux.tar.gz -C ./bin" +if [ ! -d ${DATA_HOME}/log ]; then + mkdir ${DATA_HOME}/log +fi -echo "Downloading 7 Days to Die Server" -su -l livingdead -c "mkdir -p ${LIVINGDEAD_HOME}/server" -su -l livingdead -c "${LIVINGDEAD_HOME}/bin/steamcmd.sh \ - +login anonymous \ - +force_install_dir ${LIVINGDEAD_HOME}/server \ - +app_update 294420 \ - +quit" +LOGFILE="${DATA_HOME}/log/7dtd-launcher-$(date +%Y%m%d).log" -echo "Launching 7 Days to Die" -export LD_LIBRARY_PATH=$LIVINGDEAD_HOME/server -su -l livingdead -c "${LIVINGDEAD_HOME}/server/7DaysToDieServer.x86_64 \ - -configfile=${LIVINGDEAD_HOME}/serverconfig.xml \ - -logfile ${LIVINGDEAD_HOME}/server/output.log \ - -quit -batchmode -nographics -dedicated $PARAMS" +echo $(date -u) "Checking for server updates" >> ${LOGFILE} +${STEAM_HOME}/steamcmd.sh \ + +login anonymous \ + +force_install_dir ${DATA_HOME}/server \ + +app_update 294420 \ + +quit >> ${LOGFILE} + +if [ ! -f ${DATA_HOME}/serverconfig.xml ]; then + echo $(date -u) "Installing default serverconfig.xml into ${DATA_HOME}/serverconfig.xml" >> ${LOGFILE} + echo $(date -u) "Make sure to update the configuration and restart your server." >> ${LOGFILE} + cp ${DATA_HOME}/server/serverconfig.xml ${DATA_HOME}/serverconfig.xml +fi + +echo $(date -u) "Launching 7 Days to Die Server" >> ${LOGFILE} +export LD_LIBRARY_PATH=${DATA_HOME}/server:$LD_LIBRARY_PATH +${DATA_HOME}/server/7DaysToDieServer.x86_64 \ + -configfile=${DATA_HOME}/serverconfig.xml \ + -logfile ${DATA_HOME}/log/7dtd-server-$(date +%Y%m%d).log \ + -quit -batchmode -nographics -dedicated ${PARAMS} diff --git a/Dockerfile b/Dockerfile index 705b7ef..dba3993 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,28 @@ + FROM debian:latest +LABEL maintainer="mudfly " + +RUN dpkg --add-architecture i386 && \ + apt-get update && \ + apt-get install -y \ + curl \ + lib32gcc1 \ + xmlstarlet && \ + apt-get clean all + +ENV STEAM_HOME="/steam" +ENV DATA_HOME="/data" -MAINTAINER mudfly +RUN /usr/sbin/useradd -d ${DATA_HOME} -M -s /bin/bash zed && \ + /bin/mkdir ${STEAM_HOME} && \ + /bin/chown -R zed:zed ${STEAM_HOME} -# Install dependencies -RUN dpkg --add-architecture i386 && apt-get update && apt-get install -y \ - lib32gcc1 \ - wget \ - xmlstarlet \ -&& rm -rf /var/lib/apt/lists/* +USER zed -# Creates 7dtd server as a service -RUN useradd -ms /bin/bash livingdead -WORKDIR /home/livingdead -COPY serverconfig.xml serverconfig.xml -COPY 7dtd.sh bin/7dtd -RUN chown -R livingdead:livingdead /home/livingdead +RUN curl -s https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz | tar xvz -C ${STEAM_HOME} -# Expose the default 7dtd server port -EXPOSE 8080/tcp 8081/tcp -EXPOSE 26900 26901 26902 +COPY --chown=zed:zed 7dtd.sh /7dtd.sh -CMD ["/home/livingdead/bin/7dtd"] +VOLUME ["/data"] +EXPOSE 8080/tcp 8081/tcp 26900 26901 26902 +CMD ["/bin/bash", "/7dtd.sh"] \ No newline at end of file diff --git a/README.md b/README.md index 51becc5..db9cbb6 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,15 @@ -#Docker file for a 7 Days To Die Server +# 7 Days To Die Server in a Docker Container -##Maintainers +## Maintainers Mudfly -##Build and Run Server -1. Clone this repository, and change into the directory -2. Copy `server.xml.example` to `server.xml`, and edit to your linking -3. Build the Docker image `docker build --build-arg STEAM_USER= --build-arg STEAM_PASS= --build-arg STEAM_GUARD= -t 7dtd .` -4. Start the 7 Days To Die server `./7dtd-server.run` +## Prerequisites +1. Docker Engine +2. docker-compose + +## Build and Run Server +1. Clone this repository, and change into the cloned directory +2. Build the Docker image `docker-compose build` +3. Start the 7 Days To Die server `docker-compose up -d` + +Note: This container makes use of a data volume under /srv/7dtd on the docker host, in order to persist the generated worlds between container restarts. If you would like to move this to another location, update docker-compose.yaml before launching the container. diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..00840c3 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,17 @@ +version: '2.1' + +services: + 7dtd: + build: + context: . + container_name: 7dtd + image: 7dtd:latest + restart: unless-stopped + ports: + - "8080:8080" + - "8081:8081" + - "26900:26900/udp" + - "26901:26901/udp" + - "26902:26902/udp" + volumes: + - /srv/7dtd:/data diff --git a/serverconfig.xml.example b/serverconfig.xml.example deleted file mode 100644 index 27355c2..0000000 --- a/serverconfig.xml.example +++ /dev/null @@ -1,97 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -