Skip to content
This repository has been archived by the owner on Apr 12, 2019. It is now read-only.

Limits restarts on the CheckServer monitor #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions monitor/CheckServer/CheckServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public static void main(String[] args) {
int port = Integer.parseInt(args[1]);

int failCount = 0;
long lastrestarttime = 0;

for (;;) {
Socket socket = null;
Expand Down Expand Up @@ -63,6 +64,14 @@ public static void main(String[] args) {
failCount++;

if (failCount >= 10) {
failCount = 0;

if (lastrestarttime + 600000 > System.currentTimeMillis()) {
//If restarted in the last 10 minutes, give up.
//System.out.println("CheckServer: I give up!");
break; //We break so that finally is still run.
}
lastrestarttime = System.currentTimeMillis();
try {
//System.out.println("Restart");
String command[] = { "/bin/bash", "service", "minecraft", "restart" };
Expand Down