mirror of
https://github.com/iLLeniumStudios/fivem-resource-watcher
synced 2024-02-26 13:38:52 +01:00
Support for restarting the whole server when there are 0 players
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
||||
# Container image that runs your code
|
||||
FROM alpine:3.17
|
||||
|
||||
RUN apk add --no-cache git
|
||||
RUN apk add --no-cache git jq
|
||||
|
||||
# Use icecon instead. For some reason rcon-cli doesn't send a valid command
|
||||
#ARG RCON_VERSION="0.10.2"
|
||||
|
||||
@@ -22,6 +22,7 @@ This allows you, as a server owner to have a Git Managed workflow for your serve
|
||||
| serverPort | Port of the FiveM server | false | 30120 |
|
||||
| resourcesFolder | Resources folder name | false | resources |
|
||||
| resourcesToIgnore | List of resources that you want to ignore separated by spaces and not restart when changes are made to them | false | |
|
||||
| restartServerWhen0Players | Restart the server instead when there are no players on the server. (Takes priority over `restartIndividualReesources`) | false | false |
|
||||
|
||||
## How to set up
|
||||
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ inputs:
|
||||
required: false
|
||||
default: "resources"
|
||||
restartServerWhen0Players:
|
||||
description: "Restart the server instead when there are no players on the server"
|
||||
description: "Restart the server instead when there are no players on the server. (Takes priority over restartIndividualReesources)"
|
||||
required: false
|
||||
default: false
|
||||
type: boolean
|
||||
|
||||
+17
-9
@@ -23,10 +23,14 @@ append_if_not_exists() {
|
||||
fi
|
||||
}
|
||||
|
||||
icecon_command() {
|
||||
icecon --command "$1" "${SERVER_IP}:${SERVER_PORT}" "${RCON_PASSWORD}"
|
||||
}
|
||||
|
||||
is_array_empty() {
|
||||
local array_str="$1"
|
||||
[ -z "$array_str" ]
|
||||
get_player_count() {
|
||||
response=$(curl -s "${SERVER_IP}:${SERVER_PORT}/players.json")
|
||||
player_count=$(echo "$response" | jq 'length')
|
||||
echo "$player_count"
|
||||
}
|
||||
|
||||
RESTART_INDIVIDUAL_RESOURCES=$1
|
||||
@@ -64,21 +68,25 @@ for changed in $DIFF; do
|
||||
done
|
||||
unset IFS
|
||||
|
||||
if ! is_array_empty "$resources_to_restart"; then
|
||||
if [ "$RESTART_INDIVIDUAL_RESOURCES" = true ]; then
|
||||
if [ -z "$resources_to_restart" ]; then
|
||||
echo "Nothing to restart"
|
||||
else
|
||||
player_count=$(get_player_count)
|
||||
if [ "$RESTART_SERVER_WHEN_0_PLAYERS" = true ] && [ "$player_count" -eq 0 ]; then
|
||||
echo "Will restart the whole server due to 0 players"
|
||||
icecon_command "quit"
|
||||
elif [ "$RESTART_INDIVIDUAL_RESOURCES" = true ]; then
|
||||
echo "Will restart individual resources"
|
||||
for resource in $resources_to_restart; do
|
||||
if exists_in_array "${resource}" "${IGNORED_RESOURCES}"; then
|
||||
echo "Ignoring restart of the resource ${resource}"
|
||||
else
|
||||
echo "Restarting ${resource}"
|
||||
icecon --command "ensure ${resource}" ${SERVER_IP}:${SERVER_PORT} ${RCON_PASSWORD}
|
||||
icecon_command "ensure ${resource}"
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "Will restart the whole server"
|
||||
icecon --command "quit" "${SERVER_IP}:${SERVER_PORT}" "${RCON_PASSWORD}"
|
||||
icecon_command "quit"
|
||||
fi
|
||||
else
|
||||
echo "Nothing to restart"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user