mirror of
https://github.com/YuzuZensai/palworld-server-docker.git
synced 2026-01-31 14:57:59 +00:00
feat: ✨ Add variables Env for cron feature
This commit is contained in:
@@ -15,8 +15,6 @@ RUN mv rcon-cli /usr/bin/rcon-cli
|
|||||||
RUN rm -f /var/run/crond.pid
|
RUN rm -f /var/run/crond.pid
|
||||||
COPY ./scripts/backup.sh /usr/local/bin/backup
|
COPY ./scripts/backup.sh /usr/local/bin/backup
|
||||||
RUN chmod +x /usr/local/bin/backup
|
RUN chmod +x /usr/local/bin/backup
|
||||||
RUN echo "0 3 * * * root bash /usr/local/bin/backup" > /etc/cron.d/backups-cron
|
|
||||||
RUN chmod 0644 /etc/cron.d/backups-cron
|
|
||||||
|
|
||||||
ENV PORT= \
|
ENV PORT= \
|
||||||
PUID=1000 \
|
PUID=1000 \
|
||||||
@@ -32,7 +30,10 @@ ENV PORT= \
|
|||||||
UPDATE_ON_BOOT=true \
|
UPDATE_ON_BOOT=true \
|
||||||
RCON_ENABLED=true \
|
RCON_ENABLED=true \
|
||||||
RCON_PORT=25575 \
|
RCON_PORT=25575 \
|
||||||
QUERY_PORT=27015
|
QUERY_PORT=27015 \
|
||||||
|
BACKUP_ENABLED=true \
|
||||||
|
DAYS_TO_KEEP=7 \
|
||||||
|
BACKUP_CRON_EXPRESSION="0 0 * * *"
|
||||||
|
|
||||||
COPY ./scripts/* /home/steam/server/
|
COPY ./scripts/* /home/steam/server/
|
||||||
RUN chmod +x /home/steam/server/init.sh /home/steam/server/start.sh /home/steam/server/backup.sh
|
RUN chmod +x /home/steam/server/init.sh /home/steam/server/start.sh /home/steam/server/backup.sh
|
||||||
|
|||||||
34
README.md
34
README.md
@@ -164,23 +164,33 @@ This will create a backup at `/palworld/backups/`
|
|||||||
|
|
||||||
## Setting Up Automatic Backups with Cron
|
## Setting Up Automatic Backups with Cron
|
||||||
|
|
||||||
This section guides you through the process of configuring automatic backups using Cron. Use the provided command to set up the necessary Cron job for your Palworld server within a Docker environment.
|
Setting Up Automatic Backups with Cron
|
||||||
|
|
||||||
The configured backup system automatically deletes backups older than 7 days to manage storage efficiently.
|
### Environment Variables
|
||||||
|
|
||||||
|
**DAYS_TO_KEEP:**
|
||||||
|
|
||||||
|
Description: This environment variable represents the number of days to retain backup files. It is used in the cleanup process to remove backup files older than the specified duration.
|
||||||
|
Example Usage: If set to 7, backup files older than 7 days will be deleted during the cleanup.
|
||||||
|
|
||||||
|
**BACKUP_CRON_EXPRESSION:**
|
||||||
|
|
||||||
|
Description: This environment variable defines the cron expression for scheduling automatic backups. It determines when the backup script should run at specific intervals.
|
||||||
|
Example Usage: If set to 0 2 * * *, the backup script will run every day at 2:00 AM.
|
||||||
|
|
||||||
|
**BACKUP_ENABLED:**
|
||||||
|
|
||||||
|
Description: This environment variable indicates whether automatic backups are enabled or not. If set to a non-empty value, automatic backups will be enabled; otherwise, they will be disabled.
|
||||||
|
Example Usage: If set to any non-empty string (e.g., true or 1), the backup script will be configured and executed as per the specified cron schedule.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker exec palworld-server cron /etc/cron.d/backups-cron
|
DAYS_TO_KEEP=7
|
||||||
|
BACKUP_CRON_EXPRESSION="0 2 * * *"
|
||||||
|
BACKUP_ENABLED=true
|
||||||
```
|
```
|
||||||
|
|
||||||
Additionally, to stop the cron process within the Docker container, you can use the following command:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
docker exec palworld-server service cron stop
|
|
||||||
```
|
|
||||||
|
|
||||||
This command stops the cron service within the specified container, halting the scheduled cron job.
|
|
||||||
|
|
||||||
## Editing Server Settings
|
## Editing Server Settings
|
||||||
|
|
||||||
When the server starts, a `PalWorldSettings.ini` file will be created in the following location: `<mount_folder>/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini`
|
When the server starts, a `PalWorldSettings.ini` file will be created in the following location: `<mount_folder>/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini`
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
services:
|
services:
|
||||||
palworld:
|
palworld:
|
||||||
image: thijsvanloef/palworld-server-docker:latest
|
image: test/palworld-server-docker:latest
|
||||||
|
build: .
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
container_name: palworld-server
|
container_name: palworld-server
|
||||||
ports:
|
ports:
|
||||||
@@ -15,7 +16,10 @@ services:
|
|||||||
- RCON_ENABLED=true
|
- RCON_ENABLED=true
|
||||||
- RCON_PORT=25575
|
- RCON_PORT=25575
|
||||||
- ADMIN_PASSWORD="adminPasswordHere"
|
- ADMIN_PASSWORD="adminPasswordHere"
|
||||||
- COMMUNITY=false # Enable this if you want your server to show up in the community servers tab, USE WITH SERVER_PASSWORD!
|
- COMMUNITY=false
|
||||||
|
- BACKUP_ENABLED=true
|
||||||
|
- DAYS_TO_KEEP=7
|
||||||
|
- BACKUP_CRON_EXPRESSION=0 0 * * *
|
||||||
# Enable the environment variables below if you have COMMUNITY=true
|
# Enable the environment variables below if you have COMMUNITY=true
|
||||||
# - SERVER_PASSWORD="worldofpals"
|
# - SERVER_PASSWORD="worldofpals"
|
||||||
# - SERVER_NAME="World of Pals"
|
# - SERVER_NAME="World of Pals"
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
printf "\e[0;34m***** RUNNING SCRIPTS backup.sh *****\e[0m\n"
|
|
||||||
|
|
||||||
DATE=$(date +"%Y-%m-%d_%H-%M-%S")
|
DATE=$(date +"%Y-%m-%d_%H-%M-%S")
|
||||||
DESTINATION_PATH="/palworld/backups"
|
DESTINATION_PATH="/palworld/backups"
|
||||||
FILE_PATH="${DESTINATION_PATH}/backup_palworld_${DATE}.tar.gz"
|
FILE_PATH="${DESTINATION_PATH}/backup_palworld_${DATE}.tar.gz"
|
||||||
|
|
||||||
if [ ! -f ${FILE_PATH} ]; then
|
if [ ! -f ${FILE_PATH} ]; then
|
||||||
printf "\e[0;32m***** CREATING BACKUPS FOLDER *****\e[0m\n"
|
echo "\e[0;32m***** CREATING BACKUPS FOLDER *****\e[0m\n"
|
||||||
mkdir -p "${DESTINATION_PATH}"
|
mkdir -p "${DESTINATION_PATH}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -16,4 +14,11 @@ cd /palworld/Pal/ || exit
|
|||||||
tar -zcf "$FILE_PATH" "Saved/"
|
tar -zcf "$FILE_PATH" "Saved/"
|
||||||
echo "backup created at $FILE_PATH"
|
echo "backup created at $FILE_PATH"
|
||||||
|
|
||||||
find "${DESTINATION_PATH}" -type f -name "backup_palworld_*.tar.gz" -ctime +7 -exec rm -f {} \;
|
if [[ -n "${DAYS_TO_KEEP}" && "${DAYS_TO_KEEP}" =~ ^[0-9]+$ ]]; then
|
||||||
|
echo "DAYS_TO_KEEP=${DAYS_TO_KEEP}"
|
||||||
|
find "${DESTINATION_PATH}" -type f -mtime +"${DAYS_TO_KEEP}" -exec rm {} \;
|
||||||
|
else
|
||||||
|
echo "DAYS_TO_KEEP is not a valid number."
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
printf "\e[0;34m***** RUNNING SCRIPTS init.sh *****\e[0m\n"
|
|
||||||
|
|
||||||
if [[ ! "${PUID}" -eq 0 ]] && [[ ! "${PGID}" -eq 0 ]]; then
|
if [[ ! "${PUID}" -eq 0 ]] && [[ ! "${PGID}" -eq 0 ]]; then
|
||||||
printf "\e[0;32m*****EXECUTING USERMOD*****\e[0m\n"
|
printf "\e[0;32m*****EXECUTING USERMOD*****\e[0m\n"
|
||||||
usermod -o -u "${PUID}" steam
|
usermod -o -u "${PUID}" steam
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
printf "\e[0;34m***** RUNNING SCRIPTS start.sh *****\e[0m\n"
|
|
||||||
|
|
||||||
STARTCOMMAND="./PalServer.sh"
|
STARTCOMMAND="./PalServer.sh"
|
||||||
|
|
||||||
if [ -n "${PORT}" ]; then
|
if [ -n "${PORT}" ]; then
|
||||||
@@ -69,6 +67,21 @@ if [ -n "${RCON_PORT}" ]; then
|
|||||||
sed -i "s/RCONPort=[0-9]*/RCONPort=$RCON_PORT/" /palworld/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini
|
sed -i "s/RCONPort=[0-9]*/RCONPort=$RCON_PORT/" /palworld/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ -n "${BACKUP_ENABLED}" ]]; then
|
||||||
|
echo "BACKUP_ENABLED=${BACKUP_ENABLED}"
|
||||||
|
|
||||||
|
if [[ -z "${BACKUP_CRON_EXPRESSION}" ]]; then
|
||||||
|
printf "\e[0;31m***** BACKUP_CRON_EXPRESSION NOT SET *****\e[0m\n"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "BACKUP_CRON_EXPRESSION=${BACKUP_CRON_EXPRESSION}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "${BACKUP_CRON_EXPRESSION} root bash /usr/local/bin/backup" > /etc/cron.d/backups-cron
|
||||||
|
chmod 0644 /etc/cron.d/backups-cron
|
||||||
|
cron /etc/cron.d/backups-cron
|
||||||
|
fi
|
||||||
|
|
||||||
# Configure RCON settings
|
# Configure RCON settings
|
||||||
cat >~/.rcon-cli.yaml <<EOL
|
cat >~/.rcon-cli.yaml <<EOL
|
||||||
host: localhost
|
host: localhost
|
||||||
|
|||||||
Reference in New Issue
Block a user