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

Add e.g. Discord notification on autoupdate #15

Closed
1 task done
FlickyFlack opened this issue Jan 30, 2024 · 7 comments · Fixed by #19
Closed
1 task done

Add e.g. Discord notification on autoupdate #15

FlickyFlack opened this issue Jan 30, 2024 · 7 comments · Fixed by #19
Labels
feature-request 🚀 New feature request

Comments

@FlickyFlack
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Feature description

I'd really like some kind of notification to an external service like discord when supervisord has detected/installed an update to the gameserver.

Using the following vars added / modified to the compose file:

Variable Default Contraints Description
SERVER_NAME Enshrouded Server string The name of the server and the Discord Notification Bot (if enabled)
AVATAR_URL string The Profile Picture of the Discord Bot that sends update notifications
notifyURL string Discord Webhook Link. Documentation can be found here

A simple push using curl could look like this:

curl -i -H "Accept: application/json" -H "Content-Type:application/json" -X POST --data "{\"username\": \"$(SERVER_NAME)\", \"avatar_url\": \"$(AVATAR_URL)\", \"content\": \"${MESSAGE}\"}" ${notifyURL}

While $(MESSAGE) is the literal string that is beeing pushed using the discord webhook.

@FlickyFlack FlickyFlack added the feature-request 🚀 New feature request label Jan 30, 2024
@FlickyFlack FlickyFlack changed the title Add e.g. Discord notification once the game got updated via autoupdate Add e.g. Discord notification on autoupdate Jan 30, 2024
@FlickyFlack
Copy link
Author

To add to this, the curl could be used for various logs beeing pushed to the discord webhook, e.g. the player join/leave notification that is beeing read from the service logs

@cp-fabian-pittroff
Copy link
Member

Hey, I will look into it. But I probably wont add so specific usecases. I could however expose a environment variable to hook into an update event. So you could execute some logic before and or after it triggered (e.g. sending the discord webhook).

The other one with player join/leave is more complicated. For those usecases, it will probably be better, to manage those events outside of the container.

cp-fabian-pittroff added a commit that referenced this issue Feb 3, 2024
feat: added hooks to execute custom shell scripts (resolves #15)
@cp-fabian-pittroff
Copy link
Member

Hey, I'm preparing a new develop build with initially two hooks. So if you wanna try it out, it is available in both dev images.

Variable Description WIP
BOOTSTRAP_HOOK Command to run after generel bootstrap ⚠️
UPDATE_POST_HOOK Command to run after update ⚠️

For your Discord webhook you can just use the UPDATE_POST_HOOK. Curl is already installed in that image.

@MrQu33f MrQu33f mentioned this issue Feb 5, 2024
1 task
@cp-fabian-pittroff
Copy link
Member

Hey @FlickyFlack, this feature is available in the latest dev and dev-proton image. Could you check if you can run your webhooks with that?

@cp-fabian-pittroff cp-fabian-pittroff added the waiting for feedback Waiting for additional info label Feb 5, 2024
@FlickyFlack
Copy link
Author

@cp-fabian-pittroff I'll check it out later today, thanks for the implementation!

@FlickyFlack
Copy link
Author

FlickyFlack commented Feb 6, 2024

I've unexpectedly got some time so I got around to testing:
Its not possible to use the full curl command in the compose file, so I got around by attaching a new "scripts" volume that contains the necessary start/update/stop.sh files.

Everything is working as expected! Nice work!

This is my current compose.yaml:

version: "3"
services:
  enshrouded:
    image: mornedhels/enshrouded-server:dev
    container_name: enshrouded
    hostname: enshrouded
    restart: unless-stopped
    stop_grace_period: 90s
    ports:
      - "15636-15637:15636-15637/udp"
    volumes:
      - ./game:/opt/enshrouded
      - ./scripts:/opt/scripts
    environment:
      - SERVER_NAME=<Redacted>
      - SERVER_PASSWORD=<Redacted>
      - UPDATE_CRON=*/30 * * * *
      - PUID=4711
      - PGID=4711
      - BOOTSTRAP_HOOK=/opt/scripts/boot.sh
      - UPDATE_POST_HOOK=/opt/scripts/update.sh
      - STEAM_API_KEY=<Redacted>
      - STEAM_API_PUBLIC_IP=<Redacted>

A sample boot.sh that includes the current version:

#!/bin/bash

SERVER_NAME=<Redacted>
AVATAR_URL='https://img.tapimg.net/market/images/FgKPi--ILo6TZ0nSZlQoULiJH03l.png/appicon'
MESSAGE="The Enshrouded Server has been started with version"
NOTIFY_URL=<Redacted>
CURRENT_VERSION=$(cat /opt/enshrouded/current_version)
MESSAGE="${MESSAGE} ${CURRENT_VERSION}"

curl -i -H "Accept: application/json" -H "Content-Type:application/json" -X POST --data "{\"username\":\"${SERVER_NAME}\",\"avatar_url\":\"${AVATAR_URL}\",\"content\":\"${MESSAGE}\"}" ${NOTIFY_URL}

image

@FlickyFlack
Copy link
Author

For easier adminstration I've also added an incredibly basic script that helps my "non Admin friends" in administrating the server.
I'll just dump them here, in case someone might need it:

server.sh (The main adminstration script, located in the root directory of the compose.yaml)

#!/bin/bash

case "$1" in
  "start")
    docker-compose up -d
    ;;
  "stop")
    docker-compose down
    ~/enshroudedserver/scripts/stop.sh
    ;;
  "update")
    docker-compose exec enshrouded supervisorctl start enshrouded-force-update
    ;;
  "restart")
    docker-compose down
    ~/enshroudedserver/scripts/stop.sh > /dev/null 2>&1
    docker-compose up -d
    ;;
  *)
    echo "Usage: $0 {start|stop|update|restart}"
    exit 1
    ;;
esac

exit 0

stop.sh (message beeing sent via discord webhook when the server stops, defaulting to an Enshrouded Profile Picture)

SERVER_NAME='<Username of the Discord Bot sending the message>' 
AVATAR_URL='https://img.tapimg.net/market/images/FgKPi--ILo6TZ0nSZlQoULiJH03l.png/appicon'
MESSAGE='The Enshrouded Server has been stopped'
NOTIFY_URL='<Discord-Webhook-Link>'

curl -i -H "Accept: application/json" -H "Content-Type:application/json" -X POST --data "{\"username\":\"${SERVER_NAME}\",\"avatar_url\":\"${AVATAR_URL}\",\"content\":\"${MESSAGE}\"}" ${NOTIFY_URL}

The Server Name, Avatar_URL and message can be customized as you see fit.

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

Successfully merging a pull request may close this issue.

2 participants