Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Add ENV Crontab - reusable #101

Open
doomhound188 opened this issue Sep 17, 2024 · 0 comments
Open

PR: Add ENV Crontab - reusable #101

doomhound188 opened this issue Sep 17, 2024 · 0 comments

Comments

@doomhound188
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant