Skip to content

Commit

Permalink
Merge pull request #19 from mornedhels/feature/hooks
Browse files Browse the repository at this point in the history
feat: added hooks to execute custom shell scripts (resolves #15)
  • Loading branch information
cp-fabian-pittroff authored Feb 3, 2024
2 parents afb4ddf + 9870576 commit 7fc36ef
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 19 deletions.
49 changes: 30 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ updates and cleanup.

## Environment Variables

| Variable | Required | Default | Contraints | Description | WIP |
|------------------------|:--------:|---------------------|-----------------------|------------------------------------------------------------------------------------------------------------------------------|:---:|
| `SERVER_NAME` | | `Enshrouded Server` | string | The name of the server ||
| `SERVER_PASSWORD` | | | string | The password for the server | |
| `SERVER_SLOT_COUNT` | | `16` | integer (1-16) | Max allowed concurrent players | |
| `SERVER_PORT` | | `15636` | integer | The game port for the server | |
| `SERVER_QUERYPORT` | | `15637` | integer | The steam query port for the server | |
| `SERVER_IP` | | `0.0.0.0` | string (ipv4) | Server IP for internal network configuration | |
| `SERVER_SAVE_DIR` | | `./savegame` | string | Folder for savegames (relative and absolute paths are supported) | |
| `SERVER_LOG_DIR` | | `./logs` | string | Folder for logs (relative and absolute paths are supported) | |
| `PUID` | | `4711` | integer | The UID to run server as (file permission) | |
| `PGID` | | `4711` | integer | The GID to run server as (file permission) | |
| `UPDATE_CRON` | | | string (cron format) | Update game server files cron (eg. `*/30 * * * *` check for updates every 30 minutes) | |
| `UPDATE_CHECK_PLAYERS` | | `false` | boolean (true, false) | Should the update check if someone is connected | |
| `BACKUP_CRON` | | | string (cron format) | Backup game server files cron (eg. `*/15 * * * *` backup saves every 15 minutes) - don't set cron under 10 minutes | ⚠️ |
| `BACKUP_DIR` | | `./backup` | string | Folder for backups (relative and absolute paths are supported) | ⚠️ |
| `BACKUP_MAX_COUNT` | | `0` | integer | Number of backups to keep (0 means infinite) | ⚠️ |
| `GAME_BRANCH` | | `public` | string | Steam branch (eg. testing) of the Enshrouded server | |
| `STEAMCMD_ARGS` | | `validate` | string | Additional steamcmd args for the updater | |
| Variable | Required | Default | Contraints | Description | WIP |
|------------------------|:--------:|---------------------|-----------------------|--------------------------------------------------------------------------------------------------------------------|:---:|
| `SERVER_NAME` | | `Enshrouded Server` | string | The name of the server ||
| `SERVER_PASSWORD` | | | string | The password for the server | |
| `SERVER_SLOT_COUNT` | | `16` | integer (1-16) | Max allowed concurrent players | |
| `SERVER_PORT` | | `15636` | integer | The game port for the server | |
| `SERVER_QUERYPORT` | | `15637` | integer | The steam query port for the server | |
| `SERVER_IP` | | `0.0.0.0` | string (ipv4) | Server IP for internal network configuration | |
| `SERVER_SAVE_DIR` | | `./savegame` | string | Folder for savegames (relative and absolute paths are supported) | |
| `SERVER_LOG_DIR` | | `./logs` | string | Folder for logs (relative and absolute paths are supported) | |
| `PUID` | | `4711` | integer | The UID to run server as (file permission) | |
| `PGID` | | `4711` | integer | The GID to run server as (file permission) | |
| `UPDATE_CRON` | | | string (cron format) | Update game server files cron (eg. `*/30 * * * *` check for updates every 30 minutes) | |
| `UPDATE_CHECK_PLAYERS` | | `false` | boolean (true, false) | Should the update check if someone is connected | |
| `BACKUP_CRON` | | | string (cron format) | Backup game server files cron (eg. `*/15 * * * *` backup saves every 15 minutes) - don't set cron under 10 minutes | |
| `BACKUP_DIR` | | `./backup` | string | Folder for backups (relative and absolute paths are supported) | |
| `BACKUP_MAX_COUNT` | | `0` | integer | Number of backups to keep (0 means infinite) | |
| `GAME_BRANCH` | | `public` | string | Steam branch (eg. testing) of the Enshrouded server | |
| `STEAMCMD_ARGS` | | `validate` | string | Additional steamcmd args for the updater | |

All environment Variables prefixed with SERVER, are the available enshrouded_server.json options (
see [Enshrouded Docs](https://enshrouded.zendesk.com/hc/en-us/articles/16055441447709-Dedicated-Server-Configuration))
Expand All @@ -43,6 +43,17 @@ see [Enshrouded Docs](https://enshrouded.zendesk.com/hc/en-us/articles/160554414
* STEAM_API_KEY is only needed for the update cron, to check if the server is empty. You can get a key from
[Steam](https://steamcommunity.com/dev/apikey). If not supplied, the check will be skipped.

### Hooks

| Variable | Description | WIP |
|--------------------|----------------------------------------|:---:|
| `BOOTSTRAP_HOOK` | Command to run after generel bootstrap | ⚠️ |
| `UPDATE_POST_HOOK` | Command to run after update | ⚠️ |

The scripts will wait for the hook to resolve/return before continuing.

⚠️: Work in Progress

## Image Tags

| Tag | Virtualization | Description |
Expand Down
4 changes: 4 additions & 0 deletions scripts/default/defaults
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ BACKUP_CRON=${BACKUP_CRON:-}
BACKUP_DIR=${BACKUP_DIR:-backups}
BACKUP_MAX_COUNT=${BACKUP_MAX_COUNT:-0}

# Hooks
BOOTSTRAP_HOOK=${BOOTSTRAP_HOOK:-}
UPDATE_POST_HOOK=${UPDATE_POST_HOOK:-}

# MISC
PUID=${PUID:-4711}
PGID=${PGID:-4711}
Expand Down
7 changes: 7 additions & 0 deletions scripts/default/enshrouded-bootstrap-shared
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ prepareSteamA2sPythonLibrary() {
pip3 install python-a2s==1.3.0
}

bootstrapHook() {
if [ -n "$BOOTSTRAP_HOOK" ]; then
info "Running bootstrap hook: $BOOTSTRAP_HOOK"
eval "$BOOTSTRAP_HOOK"
fi
}

updateOrCreateEnshroudedServerConfig() {
if [[ ! -e ${install_path}/enshrouded_server.json ]]; then
mkdir -p ${install_path}
Expand Down
8 changes: 8 additions & 0 deletions scripts/default/enshrouded-updater-shared
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ doUpdate() {
fi
setCurrentVersion
supervisorctl start enshrouded-server
updatePostHook

clearLock "$pidfile"
}
Expand Down Expand Up @@ -94,6 +95,13 @@ setCurrentVersion() {
echo "$latest_version" >"$version_file_path"
}

updatePostHook() {
if [ -n "$UPDATE_POST_HOOK" ]; then
info "Running update post hook: $UPDATE_POST_HOOK"
eval "$UPDATE_POST_HOOK"
fi
}

shutdown() {
debug "Received signal to shut down enshrouded-updater"
clearLock "$pidfile"
Expand Down
1 change: 1 addition & 0 deletions scripts/proton/enshrouded-bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ main() {
prepareEnshroudedAppFolders
updateOrCreateEnshroudedServerConfig
prepareSteamA2sPythonLibrary
bootstrapHook

# no proton bootstrap needed

Expand Down
1 change: 1 addition & 0 deletions scripts/wine/enshrouded-bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ main() {
prepareEnshroudedAppFolders
updateOrCreateEnshroudedServerConfig
prepareSteamA2sPythonLibrary
bootstrapHook

bootstrapWine

Expand Down

0 comments on commit 7fc36ef

Please sign in to comment.