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
|
# Container image that runs your code
|
||||||
FROM alpine:3.17
|
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
|
# Use icecon instead. For some reason rcon-cli doesn't send a valid command
|
||||||
#ARG RCON_VERSION="0.10.2"
|
#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 |
|
| serverPort | Port of the FiveM server | false | 30120 |
|
||||||
| resourcesFolder | Resources folder name | false | resources |
|
| 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 | |
|
| 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
|
## How to set up
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -23,7 +23,7 @@ inputs:
|
|||||||
required: false
|
required: false
|
||||||
default: "resources"
|
default: "resources"
|
||||||
restartServerWhen0Players:
|
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
|
required: false
|
||||||
default: false
|
default: false
|
||||||
type: boolean
|
type: boolean
|
||||||
|
|||||||
+17
-9
@@ -23,10 +23,14 @@ append_if_not_exists() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
icecon_command() {
|
||||||
|
icecon --command "$1" "${SERVER_IP}:${SERVER_PORT}" "${RCON_PASSWORD}"
|
||||||
|
}
|
||||||
|
|
||||||
is_array_empty() {
|
get_player_count() {
|
||||||
local array_str="$1"
|
response=$(curl -s "${SERVER_IP}:${SERVER_PORT}/players.json")
|
||||||
[ -z "$array_str" ]
|
player_count=$(echo "$response" | jq 'length')
|
||||||
|
echo "$player_count"
|
||||||
}
|
}
|
||||||
|
|
||||||
RESTART_INDIVIDUAL_RESOURCES=$1
|
RESTART_INDIVIDUAL_RESOURCES=$1
|
||||||
@@ -64,21 +68,25 @@ for changed in $DIFF; do
|
|||||||
done
|
done
|
||||||
unset IFS
|
unset IFS
|
||||||
|
|
||||||
if ! is_array_empty "$resources_to_restart"; then
|
if [ -z "$resources_to_restart" ]; then
|
||||||
if [ "$RESTART_INDIVIDUAL_RESOURCES" = true ]; 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"
|
echo "Will restart individual resources"
|
||||||
for resource in $resources_to_restart; do
|
for resource in $resources_to_restart; do
|
||||||
if exists_in_array "${resource}" "${IGNORED_RESOURCES}"; then
|
if exists_in_array "${resource}" "${IGNORED_RESOURCES}"; then
|
||||||
echo "Ignoring restart of the resource ${resource}"
|
echo "Ignoring restart of the resource ${resource}"
|
||||||
else
|
else
|
||||||
echo "Restarting ${resource}"
|
echo "Restarting ${resource}"
|
||||||
icecon --command "ensure ${resource}" ${SERVER_IP}:${SERVER_PORT} ${RCON_PASSWORD}
|
icecon_command "ensure ${resource}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
echo "Will restart the whole server"
|
echo "Will restart the whole server"
|
||||||
icecon --command "quit" "${SERVER_IP}:${SERVER_PORT}" "${RCON_PASSWORD}"
|
icecon_command "quit"
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
echo "Nothing to restart"
|
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user