docker-gameserver icon indicating copy to clipboard operation
docker-gameserver copied to clipboard

PR: Add ENV Crontab - reusable

Open doomhound188 opened this issue 1 year ago • 0 comments

Hi there,

I have updated the Dockerfile.pw to include environment variables for adding Crontabs for monitor, update and backup.

Please consider adding this, I have only tested with pwserver and confirmed it is working but it should be reusable across all games as it uses the linuxgsm gameserver manager.

Dockerfile.pw

#
# LinuxGSM Palworld Dockerfile
#
# https://github.com/GameServerManagers/docker-gameserver
#

FROM gameservermanagers/linuxgsm:ubuntu-22.04
LABEL maintainer="LinuxGSM <[email protected]>"

ARG SHORTNAME=pw
ENV GAMESERVER=pwserver

# Default cron schedules (can be overridden in docker-compose)
ENV MONITOR_CRON="*/5 * * * *"
ENV UPDATE_CRON="*/30 * * * *"
ENV FORCE_UPDATE_CRON="30 4 * * *"
ENV UPDATE_LGSM_CRON="0 0 * * 0"
ENV BACKUP_CRON="0 5 * * *"

WORKDIR /app

## Auto install game server requirements
RUN depshortname=$(curl --connect-timeout 10 -s https://raw.githubusercontent.com/GameServerManagers/LinuxGSM/master/lgsm/data/ubuntu-22.04.csv |awk -v shortname="pw" -F, '$1==shortname {$1=""; print $0}') \
  && if [ -n "${depshortname}" ]; then \
  echo "**** Install ${depshortname} ****" \
  && apt-get update \
  && apt-get install -y ${depshortname} cron \
  && apt-get -y autoremove \
  && apt-get clean \
  && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*; \
  fi

# Set up cron jobs dynamically based on environment variables
RUN echo "Setting up cron jobs" \
  && echo "$MONITOR_CRON /app/$GAMESERVER monitor > /dev/null 2>&1" >> /etc/crontab \
  && echo "$UPDATE_CRON /app/$GAMESERVER update > /dev/null 2>&1" >> /etc/crontab \
  && echo "$FORCE_UPDATE_CRON /app/$GAMESERVER force-update > /dev/null 2>&1" >> /etc/crontab \
  && echo "$UPDATE_LGSM_CRON /app/$GAMESERVER update-lgsm > /dev/null 2>&1" >> /etc/crontab \
  && echo "$BACKUP_CRON /app/$GAMESERVER backup > /dev/null 2>&1" >> /etc/crontab \
  && chmod 0644 /etc/crontab \
  && crontab /etc/crontab

# Run cron in the background
RUN service cron start

HEALTHCHECK --interval=1m --timeout=1m --start-period=2m --retries=1 CMD /app/entrypoint-healthcheck.sh || exit 1

RUN date > /build-time.txt

ENTRYPOINT ["/bin/bash", "./entrypoint.sh"]

compose.yml

services:
  # bind mount example
  linuxgsm-pw:
    image: gameservermanagers/gameserver:pw
    # image: ghcr.io/gameservermanagers/gameserver:pw
    container_name: pwserver
    environment:
      # Cron job environment variables
      MONITOR_CRON: "*/5 * * * *"
      UPDATE_CRON: "*/30 * * * *"
      FORCE_UPDATE_CRON: "30 4 * * *"
      UPDATE_LGSM_CRON: "0 0 * * 0"
      BACKUP_CRON:"5 * * * *"
    restart: unless-stopped
    volumes:
      - ./pwserver:/data
    network_mode: host

Thank you for your consideration.

doomhound188 avatar Sep 17 '24 12:09 doomhound188