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

Introduce to start or stop gameserver remotly via webho… #174

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

masonen
Copy link

@masonen masonen commented Feb 3, 2024

Summary

This PR introduces the possiblity to controll the gameserver status (start & stop the server) via a webhook

Motivation

Currently the dedicated servers still face a bug where pals are loosing sanity or starve when no player is connected and they get stuck. A current workaround is to stop the server while no one is active. While this bug is of course not in scope of this project i still consider the changes valuable to the project.

Since my servers are used by a small defined group of people which dont have direct CLI access to my host machines (and should not get it) an incomming webhook is a good solution to allow them to controll the serverstatus. Its not in the scope of this project how the webhook is accessed by the "outside world". The hoster can decide on how to make this webhooks availiable to the users/admins of the servers. In my case im currently building a discord bot to access the webhooks securely inside my network without publicly exposing the webhooks, other usecases might include direct web access, web integrations and many more (up to the server maintainer.

Just stoping the server via RCON is ofcourse working but this will also terminate (and restart) the container if its set to "unless-stopped". If restart policy is set to "on-error" the container will keep stopped, but without access to the host one can not start it.

Other scenarios i was considering was a docker in docker setup where i will have the webhooks handle in a container thet spawn the server container. Was working fine but it might overwhelm people to set up on their own.

Changes included

  • rework of servermanager to handle the spawn of the webhook if envvar is set. Extract all other functionalities regarding server handling or termination handling to own script
  • introduction of remotestart and remote stop script which is used by the webhook
  • introduction of new webhook outputs related to the remote controll webhooks
  • introduce a build layer to the dockerfile that builds the webhook binary from source (https://github.com/adnanh/webhook)
  • small fixesin default.env (spaces only allowed inside quotes), fixes in envvars of docker file

…oks handled by the container. Rework of term_handler. Rework of webhook.sh.
#curl --ssl-no-revoke -H "Content-Type: application/json" -X POST -d "$(generate_post_data "$title" "$description" "$color")" "$WEBHOOK_URL"
# Prod Curl
curl --silent --ssl-no-revoke -H "Content-Type: application/json" -X POST -d "$(generate_post_data "$title" "$description" "$color")" "$WEBHOOK_URL"
if [ ${WEBHOOK_ENABLED:false} == "true" ]; then
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make usage of webhooks more convienient - no mor need to check for the toogle before every call.

@jammsen jammsen added the in-review This issue planned to be reviewed or in progess of review label Feb 8, 2024
@jammsen
Copy link
Owner

jammsen commented Feb 8, 2024

Hey @masonen thanks for the pull-request and for the time you took to try to improve this repo!

Summary

This PR introduces the possiblity to controll the gameserver status (start & stop the server) via a webhook

Do you mean ability? Possibilty sounds like, it works maybe 3 out of 30 calls 🤣

Motivation

Currently the dedicated servers still face a bug where pals are loosing sanity or starve when no player is connected and they get stuck. A current workaround is to stop the server while no one is active. While this bug is of course not in scope of this project i still consider the changes valuable to the project.

They get stuck when you are online and not in render range or even in render range too, so no changes here.
What a current workaround is to stop the server? Why not turn of bEnableNonLoginPenalty? While this bug is of course not in scope of this project i still consider the changes valuable to the project. I dont get this, you say its a bug with the game, but still want me to fix it? Is that right?

Since my servers are used by a small defined group of people which dont have direct CLI access to my host machines (and should not get it) an incomming webhook is a good solution to allow them to controll the serverstatus.

So is a solution like Portainer, that way they can stop, start, resume. pause?

Its not in the scope of this project how the webhook is accessed by the "outside world".

Wait WHAT? You want me to add something that totally breaks the current server workflow AND ALSO everyone using it and dont want to offer a solution because its out of scope? What?! 😱

The hoster can decide on how to make this webhooks availiable to the users/admins of the servers. In my case im currently building a discord bot to access the webhooks securely inside my network without publicly exposing the webhooks, other usecases might include direct web access, web integrations and many more (up to the server maintainer.

This is in now way really helpful, nor new-user friendly is it? However is an adaptation, to your current problem i guess?

Just stoping the server via RCON is ofcourse working but this will also terminate (and restart) the container if its set to "unless-stopped". If restart policy is set to "on-error" the container will keep stopped, but without access to the host one can not start it.

Again isnt Portainer a solution? A non-admin friendly way, to just stop it and start it again if needed?

Other scenarios i was considering was a docker in docker setup where i will have the webhooks handle in a container thet spawn the server container. Was working fine but it might overwhelm people to set up on their own.

Docker in Docker with dedicated servers might be possible, but afaik it always comes with a heavy cost to responsetimes in ms. Would not recommend to do this.

Changes included

  • rework of servermanager to handle the spawn of the webhook if envvar is set. Extract all other functionalities regarding server handling or termination handling to own script
  • introduction of remotestart and remote stop script which is used by the webhook
  • introduction of new webhook outputs related to the remote controll webhooks
  • introduce a build layer to the dockerfile that builds the webhook binary from source (https://github.com/adnanh/webhook)
  • small fixesin default.env (spaces only allowed inside quotes), fixes in envvars of docker file

Thanks for explaining the changes, but we have a very big PR that restructures the main repo, pretty sure, this would not be compatible.

I will look into the review of the files, however is still dont understand whats the reasoning for adding this would be? Because what i read is, you dont want to change something on your end? So i should do it on my end? Why? Whats in for all of the users to use this? Why start the server via api and some scripts? Why isnt supervisord here a better or lesser solution?

Update after Review:
I did look at the code you would like to introduce but i still dont get the point and your use-case, need a better explaination of the idea, context, solution you came up with and why not another way is better. As much as i can see, this breaks a lot of compability, for introducing a very nested edge case with limited usability.

Could you please explain more around this? I would also offer a call around this, if you want @masonen maybe that way its easier to explain.

@@ -65,7 +83,7 @@ ENV DEBIAN_FRONTEND=noninteractive \
STEAMCMD_VALIDATE_FILES=true \
SERVER_SETTINGS_MODE=manual \
WEBHOOK_ENABLED=false \
WEBHOOK_URL= \
WEBHOOK_URL="" \
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces a bug with the SED scripts.


RUN apk add --update -t build-deps curl libc-dev gcc libgcc

RUN curl -L --silent -o webhook.tar.gz https://github.com/adnanh/webhook/archive/${WEBHOOK_VERSION}.tar.gz && \
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This neither a good nor secure way to install software and doesnt follow the Ansible way.

@@ -1,3 +1,17 @@
FROM golang:alpine AS build
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not going to happen in any of my images, even in multistage builds.

@@ -133,10 +151,10 @@ ENV DEBIAN_FRONTEND=noninteractive \
ADMIN_PASSWORD=adminPasswordHere \
SERVER_PASSWORD=serverPasswordHere \
PUBLIC_PORT=8211 \
PUBLIC_IP= \
PUBLIC_IP="" \
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too

RCON_ENABLED=false \
RCON_PORT=25575 \
REGION= \
REGION="" \
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too

@@ -22,6 +22,7 @@ These settings control the behavior of the Docker container:
| BACKUP_RETENTION_AMOUNT_TO_KEEP | Defines how many backups in numbers to keep | 30 | Integer |
| SERVER_SETTINGS_MODE | Determines whether settings can be modified via environment variables or via file, except `COMMUNITY_SERVER` and `MULTITHREAD_ENABLED`! | `auto` | `auto`: Settings are modified only by environment variables, manual edits will be ignored<br>`manual`: Settings are modified only by editing the file directly, environment variables are ignored |
| STEAMCMD_VALIDATE_FILES | Set to enabled SteamCMD will also validate the gameserver files, making sure nothing is corrupted and also overwrite any file changes of the source<br>See https://developer.valvesoftware.com/wiki/SteamCMD#Downloading_an_App | true | false/true |
| REMOTE_CONTROL | If enabled server will not automatically start on container start and can be started/stopped via webhook call. Stop of the gameserver does not exit the container to allow external restart. | false | false/true |
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If enabled gameserver ...

@@ -31,6 +32,15 @@ The `TZ` setting affects logging output and the backup function. [TZ identifiers

The `BACKUP_CRON_EXPRESSION` setting affects the backup function. In a Cron-Expression, you define an interval for when to run jobs. This image uses Supercronic for crons, see https://github.com/aptible/supercronic#crontab-format or https://crontab-generator.org

#### Remote Control
If you enable the container setting the Container will not autostart the gameserver, it will however provide webhooks that allow you to control the server remotely. Hooks provided are
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which setting again? Im a new user, why isnt this desribed here, its a readme right?

ALWAYS_UPDATE_ON_START=true
MULTITHREAD_ENABLED=true
COMMUNITY_SERVER=true
BACKUP_ENABLED=true
BACKUP_CRON_EXPRESSION=0 * * * *
BACKUP_CRON_EXPRESSION="0 * * * *"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduces a "" bug

@@ -74,7 +80,7 @@ ENABLE_DEFENSE_OTHER_GUILD_PLAYER=false
COOP_PLAYER_MAX_NUM=4
MAX_PLAYERS=32
SERVER_NAME=jammsen-docker-generated-###RANDOM###
SERVER_DESCRIPTION=Palworld-Dedicated-Server running in Docker by jammsen
SERVER_DESCRIPTION="Palworld-Dedicated-Server running in Docker by jammsen"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduces a bug ""

@jammsen jammsen added good first issue Good for newcomers needs-more-information Not enough information provided to help labels Feb 8, 2024
@masonen
Copy link
Author

masonen commented Feb 9, 2024

Hey. Thanks for your comments so far. I'll give an detail answer once I'm back from vacation end of this month.

I'm aware of the big pr it should have priority. I would be happy to adapt my changes once this is merged. No hurry needed I was just doing that based on my personal use case right now and it's working fine for me. Just wanted to share the idea and check if it's maybe a desired feature to start and stop the server remotely via a webhook as this would allow to start stop and restart servers via Discord bots web integrations etc. reason why I'm was doing it was the described game bug and it helps to workaround them for my servers. However the feature of remotely controlling the servers running in the container might be a feature to consider.

@jammsen
Copy link
Owner

jammsen commented Feb 9, 2024

Hey. Thanks for your comments so far. I'll give an detail answer once I'm back from vacation end of this month.

Hey @masonen sure take your time.

Looking forward to it and dont think im mean, im just honest and direct in PRs, so its not meant harsh or mean, sorry if some comments might come around like that. Its just my direct and honest opinion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers in-review This issue planned to be reviewed or in progess of review needs-more-information Not enough information provided to help
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants