Update 3 files
- /minecraft.php - /README.md - /mineautoshutdown.sh
This commit is contained in:
parent
e0c61962ec
commit
6d22b4d999
|
@ -5,6 +5,10 @@ and automatically shut it down when not in use.
|
|||
|
||||
## Installation and Usage
|
||||
|
||||
These packages require PHP, Python3, the PIP module mcstatus, and a webserver.
|
||||
|
||||
`python3 -m pip install mcstatus`
|
||||
|
||||
Install the .php file on a webserver and configure the variables as desired.
|
||||
|
||||
Place the remaining files on a server with CRON (could be the same server, just
|
||||
|
|
|
@ -1,17 +1,23 @@
|
|||
#!/bin/bash
|
||||
|
||||
DO_STATUS_URL="http://example.com/minecraft.php"
|
||||
PASSWORD="your_password_here"
|
||||
status=$(curl -s "$DO_STATUS_URL?action=status&password=$PASSWORD")
|
||||
status=$(curl -s -X POST -F "action=status" "$DO_STATUS_URL?password=$PASSWORD")
|
||||
|
||||
if [[ $status == "active" ]]; then
|
||||
players=$(python3 minestatus.py | jq ".players")
|
||||
players=$(python3 $(dirname $0)minestatus.py | jq ".players")
|
||||
|
||||
if [[ $players == 0 ]]; then
|
||||
|
||||
if [ ! -f "/tmp/minecount" ]; then
|
||||
touch /tmp/minecount
|
||||
fi
|
||||
|
||||
count=$(cat /tmp/minecount)
|
||||
|
||||
if [[ $count -gt 6 ]]; then
|
||||
echo "players $players count $count, killing"
|
||||
curl -s "$DO_STATUS_URL?action=off&password=$PASSWORD"
|
||||
curl -s -X POST -F "action=off" "$DO_STATUS_URL?password=$PASSWORD"
|
||||
echo "0" > /tmp/minecount
|
||||
else
|
||||
echo $(($count+1)) > /tmp/minecount
|
||||
|
@ -22,5 +28,5 @@ if [[ $status == "active" ]]; then
|
|||
echo "0" > /tmp/minecount
|
||||
fi
|
||||
else
|
||||
echo "not active"
|
||||
echo "not active: $status"
|
||||
fi
|
||||
|
|
|
@ -9,7 +9,7 @@ if ($_GET['password'] !== $PASSWORD) {
|
|||
exit("Invalid password.");
|
||||
}
|
||||
|
||||
if ($_GET['action'] == "on") {
|
||||
if ($_POST['action'] == "on") {
|
||||
|
||||
$out = `curl -X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
|
@ -17,31 +17,44 @@ $out = `curl -X POST \
|
|||
-d '{"type":"power_on"}' \
|
||||
"https://api.digitalocean.com/v2/droplets/$DROPLET_ID/actions"`;
|
||||
|
||||
} elseif ($_GET['action'] == "off") {
|
||||
} elseif ($_POST['action'] == "off") {
|
||||
|
||||
$out = `curl -X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
|
||||
|
||||
-d '{"type":"power_off"}' \
|
||||
"https://api.digitalocean.com/v2/droplets/$DROPLET_ID/actions"`;
|
||||
|
||||
} elseif ($_GET['action'] == "status") {
|
||||
} elseif ($_POST['action'] == "status") {
|
||||
|
||||
$out = `curl -X GET \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
|
||||
"https://api.digitalocean.com/v2/droplets/$DROPLET_ID"`;
|
||||
|
||||
} else {
|
||||
|
||||
echo "Invalid action.";
|
||||
|
||||
}
|
||||
|
||||
$json = json_decode($out, true);
|
||||
if ($out) {
|
||||
$json = json_decode($out, true);
|
||||
|
||||
if ($json['action']) {
|
||||
echo $json['action']['status'];
|
||||
} elseif ($json['droplet']) {
|
||||
echo $json['droplet']['status'];
|
||||
if ($json['action']) {
|
||||
$status = $json['action']['status'];
|
||||
} elseif ($json['droplet']) {
|
||||
$status = $json['droplet']['status'];
|
||||
}
|
||||
}
|
||||
|
||||
?><html>
|
||||
<head><title>MineCollective Minecraft Server</title></head>
|
||||
<body>
|
||||
<p>
|
||||
Press this button to turn on the server. It'll take up to 5 minutes to boot, and turn off
|
||||
after about 30 minutes of inactivity.
|
||||
</p>
|
||||
<form action="#" method="POST">
|
||||
<input type="hidden" name="action" value="on" />
|
||||
<input type="submit" value="Turn On" />
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue
Block a user