2020-05-20 13:17:58 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
current_uptime() {
|
|
|
|
echo $(awk '{print $1}' /proc/uptime | cut -d . -f 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
java_running() {
|
|
|
|
[[ $( ps -a -o stat,comm | grep 'java' | awk '{ print $1 }') =~ ^S.*$ ]]
|
|
|
|
}
|
|
|
|
|
2021-01-02 17:27:03 +00:00
|
|
|
java_process_exists() {
|
|
|
|
[[ -n "$(ps -a -o comm | grep 'java')" ]]
|
|
|
|
}
|
|
|
|
|
2020-05-20 13:17:58 +00:00
|
|
|
rcon_client_exists() {
|
|
|
|
[[ -n "$(ps -a -o comm | grep 'rcon-cli')" ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
mc_server_listening() {
|
2020-10-11 18:27:59 +00:00
|
|
|
[[ -n $(netstat -tln | grep -e "0.0.0.0:$SERVER_PORT" -e ":::$SERVER_PORT" | grep LISTEN) ]]
|
2020-05-20 13:17:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
java_clients_connected() {
|
|
|
|
local connections
|
|
|
|
connections=$(netstat -tn | grep ":$SERVER_PORT" | grep ESTABLISHED)
|
|
|
|
if [[ -z "$connections" ]] ; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
IFS=$'\n'
|
|
|
|
connections=($connections)
|
|
|
|
unset IFS
|
|
|
|
# check that at least one external address is not localhost
|
|
|
|
# remember, that the host network mode does not work with autopause because of the knockd utility
|
|
|
|
for (( i=0; i<${#connections[@]}; i++ ))
|
|
|
|
do
|
2020-10-11 18:27:59 +00:00
|
|
|
if [[ ! $(echo "${connections[$i]}" | awk '{print $5}') =~ ^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*\:)*?:?0*1$ ]] ; then
|
2020-05-20 13:17:58 +00:00
|
|
|
# not localhost
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
return 1
|
|
|
|
}
|