108 lines
2.6 KiB
Java
108 lines
2.6 KiB
Java
package mineplex.servermonitor;
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.InputStreamReader;
|
|
|
|
public class ServerMonitor
|
|
{
|
|
private static Repository _repository = new Repository();
|
|
private static int _count = 0;
|
|
|
|
public static void main (String args[])
|
|
{
|
|
_repository.initialize();
|
|
|
|
while (true)
|
|
{
|
|
if (_count % 20 == 0)
|
|
{
|
|
for (ServerStatusData statusData : _repository.retrieveOldServerStatuses())
|
|
{
|
|
String key = statusData.Address + " " + statusData.Name;
|
|
|
|
String cmd = "/home/mineplex/restartServer.sh";
|
|
Process process = null;
|
|
|
|
try
|
|
{
|
|
process = new ProcessBuilder(new String[] {"/bin/sh", "-x", cmd, statusData.Address, statusData.Name}).start();
|
|
process.waitFor();
|
|
BufferedReader reader=new BufferedReader(new InputStreamReader(process.getInputStream()));
|
|
String line = reader.readLine();
|
|
|
|
while(line != null)
|
|
{
|
|
System.out.println(line);
|
|
line=reader.readLine();
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
e.printStackTrace();
|
|
}
|
|
finally
|
|
{
|
|
if (process != null)
|
|
{
|
|
process.destroy();
|
|
}
|
|
}
|
|
|
|
System.out.println("Sent restart command to " + key + "");
|
|
}
|
|
}
|
|
|
|
if (_count % 10 == 0)
|
|
{
|
|
HashMap<String, GroupStatusData>
|
|
for (ServerStatusData statusData : _repository.retrieveGroupStatusData())
|
|
{
|
|
String key = statusData.Address + " " + statusData.Name;
|
|
|
|
String cmd = "/home/mineplex/restartServer.sh";
|
|
Process process = null;
|
|
|
|
try
|
|
{
|
|
process = new ProcessBuilder(new String[] {"/bin/sh", "-x", cmd, statusData.Address, statusData.Name}).start();
|
|
process.waitFor();
|
|
BufferedReader reader=new BufferedReader(new InputStreamReader(process.getInputStream()));
|
|
String line = reader.readLine();
|
|
|
|
while(line != null)
|
|
{
|
|
System.out.println(line);
|
|
line=reader.readLine();
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
e.printStackTrace();
|
|
}
|
|
finally
|
|
{
|
|
if (process != null)
|
|
{
|
|
process.destroy();
|
|
}
|
|
}
|
|
|
|
System.out.println("Sent restart command to " + key + "");
|
|
}
|
|
}
|
|
|
|
try
|
|
{
|
|
Thread.sleep(1000);
|
|
}
|
|
catch (InterruptedException e)
|
|
{
|
|
e.printStackTrace();
|
|
}
|
|
|
|
_count++;
|
|
_count %= 20;
|
|
}
|
|
}
|
|
}
|