diff --git a/Dockerfile b/Dockerfile index ec95036..615a34b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,42 +1,100 @@ -FROM ubuntu:16.04 +FROM debian:stable -LABEL maintainer="akshmakov@gmail.com" +ENV LGSM_DOCKER_IMAGE LinuxGameServerManager +LABEL maintainer="jkljkl1197 on github" -ENV DEBIAN_FRONTEND noninteractive +ARG DEBIAN_FRONTEND="noninteractive" -## Base System +## Ports Use can use -p port:port also +#I open bolth tcp and udp but udp in not all time necessary. +#Line 1 commun ports steam tcp +#Line 2 commun ports steam udp +#Line 3 Rcon and Web port for some server update agent tcp +#Line 4 Rcon and Web port for some server update agent udp +EXPOSE 27015:27015 7777:7777 7778:7778 \ + 27015:27015/udp 7777:7777/udp 7778:7778/udp \ + 27020:27020 443:443 80:80 \ + 27020:27020/udp 443:443/udp 80:80/udp + +## Base System package +# install apt-utils before because some installer deb script need it RUN dpkg --add-architecture i386 && \ - apt-get update -y && \ - apt-get install -y \ - binutils \ - mailutils \ - postfix \ - curl \ - wget \ - file \ - bzip2 \ - gzip \ - unzip \ - bsdmainutils \ - python \ - util-linux \ - ca-certificates \ - tmux \ - lib32gcc1 \ - libstdc++6 \ - libstdc++6:i386 - -ENV LGSM_DOCKER_VERSION 17.07.27 - -## lgsm.sh -RUN wget -N --no-check-certificate https://gameservermanagers.com/dl/linuxgsm.sh + apt-get update -y && \ + apt-get upgrade -y && \ + apt-get install -y --no-install-recommends apt-utils +## Tools (Optional) +#add packet you want to add here. +RUN apt-get install -y \ + nano \ + net-tools +## Dependency +RUN apt-get install -y \ + binutils \ + mailutils \ + postfix \ + bc \ + curl \ + wget \ + file \ + bzip2 \ + gzip \ + unzip \ + xz-utils \ + libmariadb2 \ + bsdmainutils \ + python \ + util-linux \ + ca-certificates \ + tmux \ + lib32gcc1 \ + libstdc++6 \ + libstdc++6:i386 \ + libstdc++5:i386 \ + libsdl1.2debian \ + default-jdk \ + lib32tinfo5 \ + speex:i386 \ + libtbb2 \ + libcurl4-gnutls-dev:i386 \ + libtcmalloc-minimal4:i386 \ + libncurses5:i386 \ + zlib1g:i386 \ + libldap-2.4-2:i386 \ + libxrandr2:i386 \ + libglu1-mesa:i386 \ + libxtst6:i386 \ + libusb-1.0-0-dev:i386 \ + libxxf86vm1:i386 \ + libopenal1:i386 \ + libgtk2.0-0:i386 \ + libdbus-glib-1-2:i386 \ + libnm-glib-dev:i386 \ + apt-transport-https \ + procps \ + locales \ + cron + +ENV LGSM_DOCKER_VERSION 17.11.0 + +## UTF-8 Probleme tmux... +RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && locale-gen +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US:en +ENV LC_ALL en_US.UTF-8 +## linuxgsm.sh +RUN wget -N --no-check-certificate https://raw.githubusercontent.com/GameServerManagers/LinuxGSM/master/linuxgsm.sh + +## if you have a permission probleme, check uid gid with the command id of the main linux user lgsm +## you need to have the same guid and uid as your real machine storage/data folder +## for me, my real user uid is 1001 so i need to create a user for the virtual docker image with the same uid ## user config -RUN adduser --disabled-password --gecos "" lgsm && \ +RUN adduser --disabled-password --gecos "" --uid 1001 lgsm && \ chown lgsm:lgsm /linuxgsm.sh && \ chmod +x /linuxgsm.sh && \ - cp /linuxgsm.sh /home/lgsm/linuxgsm - + cp /linuxgsm.sh /home/lgsm/linuxgsm.sh && \ + usermod -G tty lgsm #solve tmux script error + USER lgsm WORKDIR /home/lgsm @@ -44,7 +102,6 @@ WORKDIR /home/lgsm ENV TERM=xterm ## Docker Details - ENV PATH=$PATH:/home/lgsm COPY entrypoint.sh /entrypoint.sh diff --git a/README.md b/README.md index 76132eb..50810cd 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,24 @@ Dockerhub https://hub.docker.com/r/akshmakov/linuxgsm/ Run Game Servers in Docker, multiplex multiple LinuxGSM deployments easily by taking advantage of Dockers port mapping. +## Easy step + +The script create a user name lgsm with a home directory path /home/lgsm/ + +Use root user of the main linux system to build and use the script + +- Download the git repo git clone ... +- Change permission to executable : chmod +x linuxgsm-docker-build.sh && chmod +x linuxgsm-docker.sh +- Edit DockerFile and open the proper Ports for the server type you want to install(default steam base 777[7-8], 2015...) +- Execute linuxgsm-docker-build.sh +- Edit some variable at the top of the linuxgsm-docker.sh script +- Execute linuxgsm-docker.sh all you need is in this script + +if you want to edit server config from main linux system you need to have lgsm user as the same uid than in docker for the user or the owner ship going to be diffrent in container and the main linux system get permission issue or need to chown it but you can't do that from the main linux system because the user for the chown is on a other os... + + +### After this line the documentation is out updated but most of it is usefull + ## Image Tags - `latest` `base` - base image with linuxgsm.sh script and user setup @@ -96,7 +114,7 @@ then any extended image may be run as such ``` # build the custom image $ docker build -tag local/linuxgsm:$SERVERNAME . -# start the server +sudo docker run --name arkserver --rm -it -d -v "/home/lgsm/:/home/lgsm" lgsm-docker bash# start the server $ docker run -d --name my-custom-server local/linuxgsm:$SERVERNAME ``` @@ -164,7 +182,7 @@ $ docker-compose stop q2server ## Container Overview -`linuxgsm.sh` script is particularly picky about paths and does things a little different from a typical daemon. +`linuxgsm-docker.sh` script is particularly picky about paths and does things a little different from a typical daemon. In particular this docker images seeks to encapsulate LinuxGSM exactly as it is, to allow for easy transition from non-docker based deployments @@ -176,7 +194,4 @@ These quirks are - Script runs server in a tmux session (Difficult to attach to output) -This Container runs `linuxgsm.sh` under a generic user `lgsm` and script and server data installed under the home directory `/home/lgsm` - - - +This Container runs `linuxgsm-docker.sh` under a generic user `lgsm` and script and server data installed under the home directory `/home/lgsm` diff --git a/entrypoint.sh b/entrypoint.sh index 9e591f9..39766ac 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -31,6 +31,4 @@ else tmux set -g status off && tmux attach 2> /dev/null fi - - exit 0 diff --git a/linuxgsm-docker-build.sh b/linuxgsm-docker-build.sh new file mode 100755 index 0000000..32e458f --- /dev/null +++ b/linuxgsm-docker-build.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +## simple building script to create the image/container +sudo docker build -t lgsm-docker . diff --git a/linuxgsm-docker.sh b/linuxgsm-docker.sh new file mode 100755 index 0000000..0741a2f --- /dev/null +++ b/linuxgsm-docker.sh @@ -0,0 +1,160 @@ +#!/bin/bash + +## can be simplified. + +## name of the docker container +InstanceName='arkserver' +## arkserver for me (it's the script name in the serveur directory) +# for you need to be the server type name of the lgsm script +ServerType='arkserver' +## Image name to run (i have build with the lgsm-build.sh) +Img='lgsm-docker' +## current path; plz execute this script from it's folder +Path=$(pwd) +## Set the Network Used by docker +Network='host' +## Set the hostname for the docker container +Hostname='LGSM' +## Set it to False if you don't have a discord custom script like me +DiscordNotifier="false" + +## check if the container already running; return (true or '') +status=$(sudo docker inspect --format="{{.State.Running}}" $InstanceName 2> /dev/null) + +fn_discord_custom_sender(){ + if [ "${DiscordNotifier}" == "true" ] + then + sleep 2 + sudo docker exec ${InstanceName} alert_discord.sh "${cmd}" + fi +} + +## need to be test +fn_exec_cmd_sender(){ + if [ "${1}" == "exec" ] + then + if [ "${2}" == "install" ] + then + sudo docker "${1}" ${InstanceName} bash /home/lgsm/linuxgsm.sh "${3}" + else + sudo docker "${1}" ${InstanceName} ${ServerType} "${2}" "${3}" + fi + else + sudo docker "${1}" ${InstanceName} + fi +} + +fn_command_support(){ + + case ${cmd} in + "install") + if [ "${3}" != "" ] + then + fn_exec_cmd_sender exec install "${3}" + else + # Get List of game server name for install + sudo docker exec ${InstanceName} bash /home/lgsm/linuxgsm.sh install + echo "enter the server name; ctrl+c to cancel" + read -a type + fn_exec_cmd_sender exec install "${type}" + fi + ;; + + "start") + fn_exec_cmd_sender exec start + fn_discord_custom_sender "${cmd}" + ;; + + "stop") + if [ "$status" == "true" ] + then + fn_exec_cmd_sender exec stop + fn_discord_custom_sender "${cmd}" + sudo docker kill ${InstanceName} + fi + ;; + + "restart") + fn_exec_cmd_sender exec restart + fn_discord_custom_sender "${cmd}" + ;; + + "update") ## update stop the server if is already running(lgsm script). + fn_exec_cmd_sender exec update + fn_discord_custom_sender "${cmd}" + ;; + + "console") + fn_exec_cmd_sender exec console + ;; + + "monitor") + fn_exec_cmd_sender exec monitor + ;; + + "validate") + fn_exec_cmd_sender exec validate + ;; + + "backup") + fn_exec_cmd_sender exec backup + ;; + + "details") + fn_exec_cmd_sender exec details + ;; + + "alerts") + fn_exec_cmd_sender exec alerts + ;; + + "conjob") + crontab -l > CronTemp + echo "* */3 * * * bash ${Path}/linuxgsm-docker.sh command bash check_version.sh >/dev/null 2>&1" >> CronTemp + crontab CronTemp + rm CronTemp + ;; + + "attach") + echo "dettach with ctrl+p & ctrl+q" + fn_exec_cmd_sender attach + ;; + + "command") + ## Need to be test (take all parameter after the first one) + sudo docker exec -it ${InstanceName} "${@:2}" + ;; + + *) + echo "Parameter invalid, exit." + exit 1 + esac + +} + + +## check if the the container already running; if not start it if command is not Stop; +if [ "${status}" != "true" ] && [ "$1" != "stop" ] +then + echo "docker container was not running. start it for you." + sudo docker rm ${InstanceName} 2> /dev/null + sudo docker run --name ${InstanceName} --restart always --net=${Network} --hostname ${Hostname} -it -d -v "/home/lgsm/:/home/lgsm" ${Img} bash 2> /dev/null +elif [ "${status}" == "true" ] +then + echo "docker container already running, append command." +else + echo "docker container not running." +fi + +## check if we have a parameter +if [ "${#}" -gt 0 ] +then + cmd=${1} + fn_command_support "${cmd}" "${2}" +else + echo $"Usage: $0 {start|stop|restart|console|monitor|update|backup|details|alerts|cronjob|attach|command|install}" + read -a cmd + fn_command_support "${cmd}" "${2}" +fi + +#sudo docker run --name arkserver --rm -it -d -v "/home/lgsm/:/home/lgsm" lgsm-docker bash $@