Skip to content

Commit

Permalink
add Auto Pause feature
Browse files Browse the repository at this point in the history
  • Loading branch information
MusclePr committed May 17, 2024
1 parent d1e3bb1 commit e42129d
Show file tree
Hide file tree
Showing 18 changed files with 1,079 additions and 97 deletions.
23 changes: 22 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
jo=1.9-1 \
jq=1.6-2.1 \
netcat-traditional=1.10-47 \
iputils-ping libpcap0.8 \
mitmproxy \
iproute2 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Expand All @@ -71,6 +74,13 @@ RUN case ${TARGETARCH} in \
&& chmod +x supercronic \
&& mv supercronic /usr/local/bin/supercronic

# install patched knockd (as same as https://github.com/itzg/docker-minecraft-server/blob/master/build/ubuntu/install-packages.sh)
RUN wget --progress=dot:giga https://github.com/Metalcape/knock/releases/download/0.8.1/knock-0.8.1-${TARGETARCH}.tar.gz -O /tmp/knock.tar.gz && \
tar -xf /tmp/knock.tar.gz -C /usr/local/ && rm /tmp/knock.tar.gz && \
ln -s /usr/local/sbin/knockd /usr/sbin/knockd && \
setcap cap_net_raw=ep /usr/local/sbin/knockd && \
find /usr/lib -name 'libpcap.so.0.8' -execdir cp '{}' libpcap.so.1 \;

# hadolint ignore=DL3044
ENV HOME=/home/steam \
PORT= \
Expand Down Expand Up @@ -102,6 +112,9 @@ ENV HOME=/home/steam \
AUTO_REBOOT_WARN_MINUTES=5 \
AUTO_REBOOT_EVEN_IF_PLAYERS_ONLINE=false \
AUTO_REBOOT_CRON_EXPRESSION="0 0 * * *" \
AUTO_PAUSE_ENABLED=false \
AUTO_PAUSE_TIMEOUT_EST=180 \
AUTO_PAUSE_KNOCK_INTERFACE=eth0 \
DISCORD_SUPPRESS_NOTIFICATIONS= \
DISCORD_WEBHOOK_URL= \
DISCORD_CONNECT_TIMEOUT=30 \
Expand Down Expand Up @@ -156,7 +169,15 @@ RUN chmod +x /home/steam/server/*.sh && \
mv /home/steam/server/backup.sh /usr/local/bin/backup && \
mv /home/steam/server/update.sh /usr/local/bin/update && \
mv /home/steam/server/restore.sh /usr/local/bin/restore && \
ln -sf /home/steam/server/rest_api.sh /usr/local/bin/rest-cli
ln -sf /home/steam/server/rest_api.sh /usr/local/bin/rest-cli && \
ln -sf /home/steam/server/rcon.sh /usr/local/bin/rcon-cli && \
ln -sf /home/steam/server/is_safe_timing.sh /usr/local/bin/is_safe_timing && \
ln -sf /home/steam/server/autopause.sh /usr/local/bin/autopause && \
ln -sf /home/steam/server/autopaused-ctl.sh /usr/local/sbin/autopaused-ctl

# install mitmproxy addons
RUN mkdir -p /home/steam/autopause/addons && \
mv /home/steam/server/PalIntercept.py ../autopause/addons/

WORKDIR /home/steam/server

Expand Down
78 changes: 73 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ It is highly recommended you set the following environment values before startin
| AUTO_REBOOT_ENABLED | Enables automatic reboots | false | true/false | 0.21.0 |
| AUTO_REBOOT_WARN_MINUTES | How long to wait to reboot the server, after the player were informed. | 5 | Integer | 0.21.0 |
| AUTO_REBOOT_EVEN_IF_PLAYERS_ONLINE | Restart the Server even if there are players online. | false | true/false | 0.21.0 |
| AUTO_PAUSE_ENABLED | Enables automatic pause (with ENABLE_PLAYER_LOGGING=true required.) | false | true/false | 0.36.0 |
| AUTO_PAUSE_TIMEOUT_EST | default 180 (seconds) describes the time between the last client disconnect and the pausing of the process (read as timeout established) | 180 | Integer | 0.36.0 |
| AUTO_PAUSE_KNOCK_INTERFACE | The docker default is eth0. Select another NIC if necessary. | eth0 | "string" | 0.36.0 |
| AUTO_PAUSE_LOG | Enable auto-pause logging | true | true/false | 0.36.0 |
| AUTO_PAUSE_DEBUG | Enable auto-pause debug logging | false | true/false | 0.36.0 |
| TARGET_MANIFEST_ID | Locks game version to corespond with Manifest ID from Steam Download Depot. | | See [Manifest ID Table](#locking-specific-game-version) | 0.27.0 |
| DISCORD_WEBHOOK_URL | Discord webhook url found after creating a webhook on a discord server. | | `https://discord.com/api/webhooks/<webhook_id>` | 0.22.0 |
| DISCORD_SUPPRESS_NOTIFICATIONS | Enables/Disables `@silent` messages for the server messages. | false | boolean | 0.34.0 |
Expand Down Expand Up @@ -292,11 +297,12 @@ It is highly recommended you set the following environment values before startin

### Game Ports

| Port | Info |
|-------|------------------|
| 8211 | Game Port (UDP) |
| 27015 | Query Port (UDP) |
| 25575 | RCON Port (TCP) |
| Port | Info |
|-------|---------------------|
| 8211 | Game Port (UDP) |
| 27015 | Query Port (UDP) |
| 25575 | RCON Port (TCP) |
| 8212 | REST API Port (TCP) |

## Using RCON

Expand Down Expand Up @@ -529,6 +535,68 @@ AUTO_REBOOT_CRON_EXPRESSION is a cron expression, in a Cron-Expression you defin
Set AUTO_REBOOT_CRON_EXPRESSION to change the set the schedule, default is everynight at midnight according to the
timezone set with TZ

## Configuring Automatic Pause

An auto-pause functionality is provided that monitors whether clients are connected to the server.

If a client is not connected for a specified time, the PalServer process will try to put into a sleep state to save power.

The auto-pause service will retry several times to avoid the timing of writing save data.

When a client attempts to connect while the process is paused, then process will be restored to a running state.

The experience for the client does not change.

In the paused state, world time is stopped.

This feature can be enabled by setting the environment variable `AUTO_PAUSE_ENABLED` to "true".

A starting, example compose file has been provided in `examples/docker-compose-autopause.yml`.

| Variable | Info | Default Values | Allowed Values |
|-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------|----------------|
| AUTO_PAUSE_ENABLED | Enables automatic pause (Puts the server to sleep to save power when there are no online players) | false | true/false |
| AUTO_PAUSE_TIMEOUT_EST | default 180 (seconds) describes the time between the last client disconnect and the pausing of the process (read as timeout established) | 180 | Integer |
| AUTO_PAUSE_KNOCK_INTERFACE | If the default interface doesn't work, check the interface using the "ip a" command inside the container. Using the loopback interface (lo) may not produce the desired results. | eth0 | "string" |
| AUTO_PAUSE_LOG | Enable auto-pause logging | true | true/false |
| AUTO_PAUSE_DEBUG | Enable auto-pause debug logging | false | true/false |

### Resume manually

A file called `.paused` is created in `/palworld` directory when the server is paused and removed when the server is resumed.

Other services may check for this file's existence before waking the server.

Alternatively, resume with the following command:

```shell
docker exec -it palworld-server autopause resume
```

### Service control manually

A `.skip-pause` file can be created in the `/palworld` directory to make the server skip autopausing,
for as long as the file is present.

Alternatively, you can control with the following command:

```shell
docker exec -it palworld-server autopause stop
docker exec -it palworld-server autopause continue
```

This `autopause stop` command is also used during automatic reboots, automatic updates, and container stops.
It is also used to shutdown command via REST API/RCON.

### With Community Server

If the environment variable `COMMUNITY` is true, A proxy server is started within the container to
maintain registration on the community server list.

The proxy server captures communication with `api.palworldgames.com`.

The auto-pause service will replay captured data in the paused state.

## Editing Server Settings

### With Environment Variables
Expand Down
16 changes: 11 additions & 5 deletions docusaurus/docs/getting-started/configuration/server-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ It is highly recommended you set the following environment values before startin
| AUTO_REBOOT_ENABLED | Enables automatic reboots | false | true/false | 0.21.0 |
| AUTO_REBOOT_WARN_MINUTES | How long to wait to reboot the server, after the player were informed. | 5 | Integer | 0.21.0 |
| AUTO_REBOOT_EVEN_IF_PLAYERS_ONLINE | Restart the Server even if there are players online. | false | true/false | 0.21.0 |
| AUTO_PAUSE_ENABLED | Enables automatic pause (with ENABLE_PLAYER_LOGGING=true required.) | false | true/false | 0.36.0 |
| AUTO_PAUSE_TIMEOUT_EST | default 180 (seconds) describes the time between the last client disconnect and the pausing of the process (read as timeout established) | 180 | Integer | 0.36.0 |
| AUTO_PAUSE_KNOCK_INTERFACE | The docker default is eth0. Select another NIC if necessary. | eth0 | "string" | 0.36.0 |
| AUTO_PAUSE_LOG | Enable auto-pause logging | true | true/false | 0.36.0 |
| AUTO_PAUSE_DEBUG | Enable auto-pause debug logging | false | true/false | 0.36.0 |
| TARGET_MANIFEST_ID | Locks game version to corespond with Manfiest ID from Steam Download Depot. | | See [Manifest ID Table](https://palworld-server-docker.loef.dev/guides/pinning-game-version#version-to-manifest-id-table) | 0.27.0 |
| DISCORD_WEBHOOK_URL | Discord webhook url found after creating a webhook on a discord server | | `https://discord.com/api/webhooks/<webhook_id>` | 0.22.0 |
| DISCORD_SUPPRESS_NOTIFICATIONS | Enables/Disables `@silent` messages for the server messages. | false | boolean | 0.34.0 |
Expand Down Expand Up @@ -112,8 +117,9 @@ It is highly recommended you set the following environment values before startin

The server needs the following ports by default.

| Port | Info |
|-------|------------------|
| 8211 | Game Port (UDP) |
| 27015 | Query Port (UDP) |
| 25575 | RCON Port (TCP) |
| Port | Info |
|-------|---------------------|
| 8211 | Game Port (UDP) |
| 27015 | Query Port (UDP) |
| 25575 | RCON Port (TCP) |
| 8212 | REST API Port (TCP) |
Loading

0 comments on commit e42129d

Please sign in to comment.