diff --git a/Dockerfile.ubuntu-1804 b/Dockerfile.ubuntu-1804 index 539c850..1bf3d7c 100644 --- a/Dockerfile.ubuntu-1804 +++ b/Dockerfile.ubuntu-1804 @@ -14,7 +14,7 @@ ENV TERM=xterm ENV LGSM_GITHUBUSER=GameServerManagers ENV LGSM_GITHUBREPO=LinuxGSM ENV LGSM_GITHUBBRANCH=develop -ENV GAMESERVER=jc3server +ENV GAMESERVER=jc2server ENV UPDATE_CHECK=1800 ENV USERNAME=linuxgsm ENV UID=1000 @@ -95,8 +95,6 @@ RUN date > /build-time.txt WORKDIR /linuxgsm -COPY entrypoint.sh /linuxgsm/entrypoint.sh - ## Add linuxgsm user RUN echo "**** Add linuxgsm user ****" \ # Create the user @@ -106,12 +104,10 @@ RUN echo "**** Add linuxgsm user ****" \ # [Optional] Add sudo support. Omit if you don't need to install software after connecting. && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ && chmod 0440 /etc/sudoers.d/$USERNAME \ - && chown $USERNAME:$USERNAME /home/$USERNAME \ - && chown -R $USERNAME:$USERNAME /linuxgsm + && chown $USERNAME:$USERNAME /home/$USERNAME HEALTHCHECK --interval=1m --timeout=1m --start-period=2m --retries=1 CMD /linuxgsm/*server monitor || exit 1 -USER linuxgsm ## Download linuxgsm.sh RUN echo "**** Download linuxgsm.sh ****" \ && set -ex \ @@ -128,11 +124,13 @@ RUN echo "**** Get LinuxGSM Modules ****" \ && mkdir -p /linuxgsm/lgsm/functions \ && mv lgsm/functions/* /linuxgsm/lgsm/functions \ && chmod +x /linuxgsm/lgsm/functions/* \ - && rm -rf /linuxgsm/LinuxGSM + && rm -rf /linuxgsm/LinuxGSM \ + && chown -R $USERNAME:$USERNAME /linuxgsm -# Add LinuxGSM cronjobs -RUN echo "**** Create Cronjob ****" -RUN (crontab -l 2>/dev/null; echo "*/30 * * * * /linuxgsm/*server update > /dev/null 2>&1") | crontab - +COPY entrypoint.sh /linuxgsm/entrypoint.sh +COPY entrypoint-user.sh /linuxgsm/entrypoint-user.sh + +RUN date > /build-time.txt ENTRYPOINT ["/init"] CMD [ "./entrypoint.sh" ] diff --git a/Dockerfile.ubuntu-2004 b/Dockerfile.ubuntu-2004 index c4f86b5..faa139a 100644 --- a/Dockerfile.ubuntu-2004 +++ b/Dockerfile.ubuntu-2004 @@ -14,7 +14,7 @@ ENV TERM=xterm ENV LGSM_GITHUBUSER=GameServerManagers ENV LGSM_GITHUBREPO=LinuxGSM ENV LGSM_GITHUBBRANCH=develop -ENV GAMESERVER=jc3server +ENV GAMESERVER=jc2server ENV UPDATE_CHECK=1800 ENV USERNAME=linuxgsm ENV UID=1000 @@ -95,8 +95,6 @@ RUN date > /build-time.txt WORKDIR /linuxgsm -COPY entrypoint.sh /linuxgsm/entrypoint.sh - ## Add linuxgsm user RUN echo "**** Add linuxgsm user ****" \ # Create the user @@ -106,12 +104,10 @@ RUN echo "**** Add linuxgsm user ****" \ # [Optional] Add sudo support. Omit if you don't need to install software after connecting. && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ && chmod 0440 /etc/sudoers.d/$USERNAME \ - && chown $USERNAME:$USERNAME /home/$USERNAME \ - && chown -R $USERNAME:$USERNAME /linuxgsm + && chown $USERNAME:$USERNAME /home/$USERNAME HEALTHCHECK --interval=1m --timeout=1m --start-period=2m --retries=1 CMD /linuxgsm/*server monitor || exit 1 -USER linuxgsm ## Download linuxgsm.sh RUN echo "**** Download linuxgsm.sh ****" \ && set -ex \ @@ -128,11 +124,13 @@ RUN echo "**** Get LinuxGSM Modules ****" \ && mkdir -p /linuxgsm/lgsm/functions \ && mv lgsm/functions/* /linuxgsm/lgsm/functions \ && chmod +x /linuxgsm/lgsm/functions/* \ - && rm -rf /linuxgsm/LinuxGSM + && rm -rf /linuxgsm/LinuxGSM \ + && chown -R $USERNAME:$USERNAME /linuxgsm -# Add LinuxGSM cronjobs -RUN echo "**** Create Cronjob ****" -RUN (crontab -l 2>/dev/null; echo "*/30 * * * * /linuxgsm/*server update > /dev/null 2>&1") | crontab - +COPY entrypoint.sh /linuxgsm/entrypoint.sh +COPY entrypoint-user.sh /linuxgsm/entrypoint-user.sh + +RUN date > /build-time.txt ENTRYPOINT ["/init"] CMD [ "./entrypoint.sh" ] diff --git a/Dockerfile.ubuntu-2204 b/Dockerfile.ubuntu-2204 index aae2c43..83b40ad 100644 --- a/Dockerfile.ubuntu-2204 +++ b/Dockerfile.ubuntu-2204 @@ -91,12 +91,8 @@ RUN tar -C / -Jxpf /tmp/s6-overlay-symlinks-noarch.tar.xz ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-symlinks-arch.tar.xz /tmp RUN tar -C / -Jxpf /tmp/s6-overlay-symlinks-arch.tar.xz -RUN date > /build-time.txt - WORKDIR /linuxgsm -COPY entrypoint.sh /linuxgsm/entrypoint.sh - ## Add linuxgsm user RUN echo "**** Add linuxgsm user ****" \ # Create the user @@ -106,12 +102,10 @@ RUN echo "**** Add linuxgsm user ****" \ # [Optional] Add sudo support. Omit if you don't need to install software after connecting. && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ && chmod 0440 /etc/sudoers.d/$USERNAME \ - && chown $USERNAME:$USERNAME /home/$USERNAME \ - && chown -R $USERNAME:$USERNAME /linuxgsm + && chown $USERNAME:$USERNAME /home/$USERNAME HEALTHCHECK --interval=1m --timeout=1m --start-period=2m --retries=1 CMD /linuxgsm/*server monitor || exit 1 -USER linuxgsm ## Download linuxgsm.sh RUN echo "**** Download linuxgsm.sh ****" \ && set -ex \ @@ -128,11 +122,13 @@ RUN echo "**** Get LinuxGSM Modules ****" \ && mkdir -p /linuxgsm/lgsm/functions \ && mv lgsm/functions/* /linuxgsm/lgsm/functions \ && chmod +x /linuxgsm/lgsm/functions/* \ - && rm -rf /linuxgsm/LinuxGSM + && rm -rf /linuxgsm/LinuxGSM \ + && chown -R $USERNAME:$USERNAME /linuxgsm + +COPY entrypoint.sh /linuxgsm/entrypoint.sh +COPY entrypoint-user.sh /linuxgsm/entrypoint-user.sh -# Add LinuxGSM cronjobs -RUN echo "**** Create Cronjob ****" -RUN (crontab -l 2>/dev/null; echo "*/30 * * * * /linuxgsm/*server update > /dev/null 2>&1") | crontab - +RUN date > /build-time.txt ENTRYPOINT ["/init"] CMD [ "./entrypoint.sh" ] diff --git a/entrypoint-user.sh b/entrypoint-user.sh new file mode 100755 index 0000000..68efe23 --- /dev/null +++ b/entrypoint-user.sh @@ -0,0 +1,78 @@ +#!/bin/bash +export HOME="/home/${USERNAME}" +# Setup game server +if [ ! -f "${GAMESERVER}" ]; then + echo -e "" + echo -e "creating ${GAMESERVER}" + echo -e "=================================" + ./linuxgsm.sh ${GAMESERVER} +fi + +# Clear functions directory if not master +if [ "${LGSM_GITHUBBRANCH}" != "master" ]; then + echo -e "not master branch, clearing functions directory" + rm -rf /linuxgsm/lgsm/functions/* +elif [ -d "/linuxgsm/lgsm/functions" ]; then + echo -e "ensure all functions are executable" + chmod +x /linuxgsm/lgsm/functions/* +fi + +# Install game server +if [ -z "$(ls -A -- "serverfiles" >/dev/null 2>&1)" ]; then + echo -e "" + echo -e "Installing ${GAMESERVER}" + echo -e "=================================" + ./${GAMESERVER} auto-install + install=1 +else + # Donate to display logo + ./${GAMESERVER} donate +fi +echo -e "" +echo -e "Starting Monitor" +echo -e "=================================" +nohup watch -n "${MONITOR_CHECK}" ./${GAMESERVER} monitor >/dev/null 2>&1 & +echo -e "monitor will check every ${MONITOR_CHECK} minutes" +echo -e "" +echo -e "Starting Update Checks" +echo -e "=================================" +nohup watch -n "${UPDATE_CHECK}" ./${GAMESERVER} update >/dev/null 2>&1 & +echo -e "update will check every $UPDATE_CHECK} minutes" + +# Update game server +if [ -z "${install}" ]; then + echo -e "" + echo -e "Checking for Update ${GAMESERVER}" + echo -e "=================================" + ./${GAMESERVER} update +fi + +echo -e "" +echo -e "Starting ${GAMESERVER}" +echo -e "=================================" +./${GAMESERVER} start +sleep 5 +./${GAMESERVER} details +sleep 2 +echo -e "Tail log files" +echo -e "=================================" +tail -F log/*/*.log + +# with no command, just spawn a running container suitable for exec's +if [ $# = 0 ]; then + tail -f /dev/null +else + # execute the command passed through docker + "$@" + + # if this command was a server start cmd + # to get around LinuxGSM running everything in + # tmux; + # we attempt to attach to tmux to track the server + # this keeps the container running + # when invoked via docker run + # but requires -it or at least -t + tmux set -g status off && tmux attach 2>/dev/null +fi + +exec "$@" diff --git a/entrypoint.sh b/entrypoint.sh index 327699f..6ffb306 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -11,13 +11,14 @@ exit_handler() { # Exit trap echo -e "Loading exit handler" trap exit_handler SIGQUIT SIGINT SIGTERM - +DISTRO="$(grep "PRETTY_NAME" /etc/os-release | awk -F = '{gsub(/"/,"",$2);print $2}')" echo -e "" echo -e "Welcome to the LinuxGSM" echo -e "================================================================================" echo -e "CURRENT TIME: $(date)" echo -e "BUILD TIME: $(cat /build-time.txt)" echo -e "GAMESERVER: ${GAMESERVER}" +echo -e "DISTRO: ${DISTRO}" echo -e "" echo -e "USER: ${USERNAME}" echo -e "UID: ${UID}" @@ -37,82 +38,19 @@ export LGSM_GITHUBBRANCH=${LGSM_GITHUBBRANCH} cd /linuxgsm || exit -# permissions -usermod -u ${UID} linuxgsm +echo -e "" +echo -e "Check Permissions" +echo -e "=================================" +echo -e "setting UID to ${UID}" +usermod -u ${UID} linuxgsm >/dev/null 2>&1 +echo -e "setting GID to ${GID}" groupmod -g ${GID} linuxgsm +echo -e "updating permissions" find /linuxgsm -user ${UID} -exec chown -h linuxgsm {} \; find /linuxgsm -group ${GID} -exec chgrp -h linuxgsm {} \; -chown -R linuxgsm:linuxgsm /linuxgsm - -# Setup game server -if [ ! -f "${GAMESERVER}" ]; then - echo -e "" - echo -e "creating ./${GAMESERVER}" - ./linuxgsm.sh ${GAMESERVER} -fi - -# Clear functions directory if not master -if [ "${LGSM_GITHUBBRANCH}" != "master" ]; then - echo -e "" - echo -e "not master branch, clearing functions directory" - rm -rf /linuxgsm/lgsm/functions/* -elif [ -d "/linuxgsm/lgsm/functions" ]; then - echo -e "" - echo -e "check all functions are executable" - chmod +x /linuxgsm/lgsm/functions/* -fi - -# Install game server -if [ -z "$(ls -A -- "serverfiles")" ]; then - echo -e "" - echo -e "Installing ${GAMESERVER}" - echo -e "=================================" - ./${GAMESERVER} auto-install - install=1 -else - # Donate to display logo - ./${GAMESERVER} donate -fi - -echo -e "Starting Monitor" -echo -e "=================================" -#cron -nohup watch -n "${UPDATE_CHECK}" ./${GAMESERVER} update >/dev/null 2>&1 & - -# Update game server -if [ -z "${install}" ]; then - echo -e "" - echo -e "Updating ${GAMESERVER}" - echo -e "=================================" - ./${GAMESERVER} update -fi +chown -R ${USERNAME}:${USERNAME} /linuxgsm echo -e "" -echo -e "Starting ${GAMESERVER}" -echo -e "=================================" -./${GAMESERVER} start -sleep 5 -./${GAMESERVER} details -sleep 2 -echo -e "Tail log files" +echo -e "Switch to user ${USERNAME}" echo -e "=================================" -tail -F log/*/*.log - -# with no command, just spawn a running container suitable for exec's -if [ $# = 0 ]; then - tail -f /dev/null -else - # execute the command passed through docker - "$@" - - # if this command was a server start cmd - # to get around LinuxGSM running everything in - # tmux; - # we attempt to attach to tmux to track the server - # this keeps the container running - # when invoked via docker run - # but requires -it or at least -t - tmux set -g status off && tmux attach 2>/dev/null -fi - -exec "$@" +exec s6-setuidgid ${USERNAME} /linuxgsm/entrypoint-user.sh