2013-10-10 18:02:21 +02:00
|
|
|
package mineplex.servermonitor;
|
|
|
|
|
2014-02-18 09:40:41 +01:00
|
|
|
import java.io.BufferedReader;
|
2014-04-27 08:26:56 +02:00
|
|
|
import java.io.File;
|
2014-07-30 06:10:52 +02:00
|
|
|
import java.io.IOException;
|
2014-02-18 09:40:41 +01:00
|
|
|
import java.io.InputStreamReader;
|
2014-07-30 06:10:52 +02:00
|
|
|
import java.text.SimpleDateFormat;
|
2014-04-27 08:26:56 +02:00
|
|
|
import java.util.AbstractMap;
|
2013-11-05 19:19:04 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
2013-11-06 10:03:02 +01:00
|
|
|
import java.util.Collections;
|
2014-07-30 06:10:52 +02:00
|
|
|
import java.util.Date;
|
2013-11-05 19:19:04 +01:00
|
|
|
import java.util.HashMap;
|
2014-01-08 21:18:52 +01:00
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Iterator;
|
2013-11-02 08:56:31 +01:00
|
|
|
import java.util.List;
|
2014-04-27 08:26:56 +02:00
|
|
|
import java.util.Map.Entry;
|
2014-07-30 06:10:52 +02:00
|
|
|
import java.util.logging.FileHandler;
|
|
|
|
import java.util.logging.Logger;
|
2013-10-10 18:02:21 +02:00
|
|
|
|
2014-08-28 23:01:37 +02:00
|
|
|
import mineplex.core.common.util.NautHashMap;
|
2014-08-01 23:56:29 +02:00
|
|
|
import mineplex.serverdata.DedicatedServer;
|
|
|
|
import mineplex.serverdata.DedicatedServerSorter;
|
|
|
|
import mineplex.serverdata.MinecraftServer;
|
|
|
|
import mineplex.serverdata.Region;
|
|
|
|
import mineplex.serverdata.ServerGroup;
|
|
|
|
import mineplex.serverdata.ServerManager;
|
|
|
|
import mineplex.serverdata.ServerRepository;
|
|
|
|
|
2013-10-10 18:02:21 +02:00
|
|
|
public class ServerMonitor
|
|
|
|
{
|
2014-08-01 23:56:29 +02:00
|
|
|
|
|
|
|
private static ServerRepository _repository = null;
|
2013-10-15 23:19:14 +02:00
|
|
|
private static int _count = 0;
|
2014-01-08 21:18:52 +01:00
|
|
|
private static HashSet<ProcessRunner> _processes = new HashSet<ProcessRunner>();
|
2014-02-18 09:40:41 +01:00
|
|
|
private static HashMap<String, Boolean> _badServers = new HashMap<String, Boolean>();
|
2013-10-10 18:02:21 +02:00
|
|
|
|
2014-07-30 06:10:52 +02:00
|
|
|
private static SimpleDateFormat _dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
|
|
|
|
private static Logger _logger = Logger.getLogger("ServerMonitor");
|
|
|
|
|
2013-10-10 18:02:21 +02:00
|
|
|
public static void main (String args[])
|
2014-04-27 08:26:56 +02:00
|
|
|
{
|
2014-08-01 23:56:29 +02:00
|
|
|
Region region = !new File("eu.dat").exists() ? Region.US : Region.EU;
|
|
|
|
_repository = ServerManager.getServerRepository(region); // Fetches and connects to server repo
|
2014-08-05 01:14:04 +02:00
|
|
|
|
2014-07-30 06:10:52 +02:00
|
|
|
File logFile = new File("monitor.log");
|
|
|
|
|
|
|
|
if (!logFile.exists())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
logFile.createNewFile();
|
|
|
|
}
|
|
|
|
catch (IOException e1)
|
|
|
|
{
|
|
|
|
e1.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
FileHandler fileHandler = new FileHandler("monitor.log");
|
|
|
|
fileHandler.setFormatter(new CustomFormatter());
|
|
|
|
_logger.addHandler(fileHandler);
|
|
|
|
_logger.setUseParentHandlers(false);
|
|
|
|
}
|
|
|
|
catch (SecurityException | IOException e1)
|
|
|
|
{
|
|
|
|
e1.printStackTrace();
|
|
|
|
}
|
|
|
|
|
2014-04-27 08:26:56 +02:00
|
|
|
HashMap<String, Entry<String, Long>> serverTracker = new HashMap<String, Entry<String, Long>>();
|
2013-10-10 18:02:21 +02:00
|
|
|
|
|
|
|
while (true)
|
2014-04-27 08:26:56 +02:00
|
|
|
{
|
2014-08-01 23:56:29 +02:00
|
|
|
Collection<ServerGroup> serverGroups = _repository.getServerGroups();
|
2014-08-14 11:10:11 +02:00
|
|
|
|
|
|
|
for (MinecraftServer deadServer : _repository.getDeadServers())
|
|
|
|
{
|
2014-08-18 21:46:23 +02:00
|
|
|
killServer(deadServer.getName(), deadServer.getPublicAddress(), "[KILLED] [DEAD] " + deadServer.getName() + ":" + deadServer.getPublicAddress(), true);
|
2014-08-14 11:10:11 +02:00
|
|
|
}
|
|
|
|
|
2014-08-01 23:56:29 +02:00
|
|
|
List<DedicatedServer> dedicatedServers = new ArrayList<DedicatedServer>(_repository.getDedicatedServers());
|
|
|
|
|
|
|
|
if (_count % 15 == 0)
|
|
|
|
{
|
|
|
|
_badServers.clear();
|
|
|
|
|
|
|
|
for (DedicatedServer serverData : dedicatedServers)
|
2014-08-14 11:10:11 +02:00
|
|
|
{
|
2014-08-01 23:56:29 +02:00
|
|
|
if (isServerOffline(serverData))
|
2014-02-18 09:40:41 +01:00
|
|
|
{
|
2014-08-26 08:56:58 +02:00
|
|
|
log("------=[OFFLINE]=------=[" + serverData.getName() + ":" + serverData.getPublicAddress() + "]=------=[OFFLINE]=------");
|
2014-08-01 23:56:29 +02:00
|
|
|
_badServers.put(serverData.getName(), true);
|
2014-02-18 09:40:41 +01:00
|
|
|
}
|
|
|
|
}
|
2014-07-01 19:23:22 +02:00
|
|
|
|
2014-08-26 08:56:58 +02:00
|
|
|
log(_badServers.size() + " bad servers.");
|
2014-02-18 09:40:41 +01:00
|
|
|
}
|
|
|
|
|
2014-08-01 23:56:29 +02:00
|
|
|
for (Iterator<DedicatedServer> iterator = dedicatedServers.iterator(); iterator.hasNext();)
|
2014-02-18 09:40:41 +01:00
|
|
|
{
|
2014-08-01 23:56:29 +02:00
|
|
|
DedicatedServer serverData = iterator.next();
|
|
|
|
|
|
|
|
if (_badServers.containsKey(serverData.getName()))
|
|
|
|
iterator.remove();
|
2014-03-29 06:32:24 +01:00
|
|
|
}
|
2014-08-01 23:56:29 +02:00
|
|
|
|
2014-08-28 23:01:37 +02:00
|
|
|
for (ServerGroup groupStatus : serverGroups)
|
2014-01-08 21:18:52 +01:00
|
|
|
{
|
2014-08-28 23:01:37 +02:00
|
|
|
NautHashMap<Integer, MinecraftServer> _serverMap = new NautHashMap<Integer, MinecraftServer>();
|
2014-01-08 21:18:52 +01:00
|
|
|
|
2014-08-28 23:01:37 +02:00
|
|
|
for (Iterator<MinecraftServer> serverIterator = groupStatus.getServers().iterator(); serverIterator.hasNext();)
|
2014-01-08 21:18:52 +01:00
|
|
|
{
|
2014-08-28 23:01:37 +02:00
|
|
|
MinecraftServer server = serverIterator.next();
|
|
|
|
int serverNum = Integer.parseInt(server.getName().split("-")[1]);
|
|
|
|
|
|
|
|
if (_serverMap.containsKey(serverNum))
|
|
|
|
{
|
|
|
|
killServer(server.getName(), server.getPublicAddress(), "[KILLED] [DUPLICATE] " + server.getName() + ":" + server.getPublicAddress(), true);
|
|
|
|
serverIterator.remove();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_serverMap.put(serverNum, server);
|
|
|
|
}
|
2014-04-27 08:26:56 +02:00
|
|
|
}
|
2014-08-28 23:01:37 +02:00
|
|
|
}
|
2014-08-01 23:56:29 +02:00
|
|
|
|
2014-08-14 14:41:04 +02:00
|
|
|
HashSet<String> onlineServers = new HashSet<String>();
|
|
|
|
|
|
|
|
for (MinecraftServer minecraftServer : _repository.getServerStatuses())
|
|
|
|
{
|
|
|
|
onlineServers.add(minecraftServer.getName());
|
2014-08-16 08:37:06 +02:00
|
|
|
|
|
|
|
if (minecraftServer.getTps() <= 17)
|
2014-08-26 08:56:58 +02:00
|
|
|
log("[Performance] " + minecraftServer.getName() + ":" + minecraftServer.getPublicAddress() + "] Running poorly at " + minecraftServer.getTps() + " TPS");
|
2014-08-14 14:41:04 +02:00
|
|
|
}
|
|
|
|
|
2014-08-01 23:56:29 +02:00
|
|
|
for (Iterator<Entry<String, Entry<String, Long>>> iterator = serverTracker.entrySet().iterator(); iterator.hasNext();)
|
|
|
|
{
|
|
|
|
Entry<String, Entry<String, Long>> entry = iterator.next();
|
|
|
|
|
2014-08-14 14:41:04 +02:00
|
|
|
if (onlineServers.contains(entry.getKey()))
|
|
|
|
iterator.remove();
|
|
|
|
else if (System.currentTimeMillis() - entry.getValue().getValue() > 20000)
|
2014-08-01 23:56:29 +02:00
|
|
|
{
|
|
|
|
String serverName = entry.getKey();
|
|
|
|
String serverAddress = entry.getValue().getKey();
|
2014-08-18 21:46:23 +02:00
|
|
|
killServer(serverName, serverAddress, "[KILLED] [SLOW-STARTUP] " + serverName + ":" + serverAddress, true);
|
2014-08-01 23:56:29 +02:00
|
|
|
iterator.remove();
|
2014-04-27 08:26:56 +02:00
|
|
|
}
|
2014-08-01 23:56:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (ServerGroup serverGroup : serverGroups)
|
|
|
|
{
|
2014-08-05 01:14:04 +02:00
|
|
|
handleGroupChanges(dedicatedServers, serverTracker, serverGroup, false);
|
2014-08-01 23:56:29 +02:00
|
|
|
}
|
2014-03-03 21:47:57 +01:00
|
|
|
|
2014-02-18 09:40:41 +01:00
|
|
|
int processWaits = 0;
|
|
|
|
|
2014-02-14 20:39:24 +01:00
|
|
|
while (_processes.size() > 0)
|
|
|
|
{
|
|
|
|
for (Iterator<ProcessRunner> iterator = _processes.iterator(); iterator.hasNext();)
|
|
|
|
{
|
|
|
|
ProcessRunner pr = iterator.next();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
pr.join(100);
|
|
|
|
}
|
|
|
|
catch (InterruptedException e)
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pr.isDone())
|
|
|
|
iterator.remove();
|
|
|
|
}
|
|
|
|
|
2014-02-18 09:40:41 +01:00
|
|
|
if (_processes.size() > 0)
|
2014-02-14 20:39:24 +01:00
|
|
|
{
|
2014-02-18 09:40:41 +01:00
|
|
|
try
|
|
|
|
{
|
2014-08-26 08:56:58 +02:00
|
|
|
log("Sleeping while processes run...");
|
2014-02-18 09:40:41 +01:00
|
|
|
Thread.sleep(6000);
|
|
|
|
}
|
|
|
|
catch (InterruptedException e)
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2014-02-14 20:39:24 +01:00
|
|
|
}
|
|
|
|
|
2014-02-18 09:40:41 +01:00
|
|
|
if (processWaits >= 10)
|
2014-02-14 20:39:24 +01:00
|
|
|
{
|
2014-08-26 08:56:58 +02:00
|
|
|
log("Killing stale processes.");
|
2014-02-14 20:39:24 +01:00
|
|
|
|
|
|
|
for (Iterator<ProcessRunner> iterator = _processes.iterator(); iterator.hasNext();)
|
|
|
|
{
|
|
|
|
iterator.next().abort();
|
|
|
|
iterator.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-18 09:40:41 +01:00
|
|
|
processWaits++;
|
2014-02-14 20:39:24 +01:00
|
|
|
}
|
2014-03-03 21:47:57 +01:00
|
|
|
|
2014-08-14 14:41:04 +02:00
|
|
|
processWaits = 0;
|
2014-02-14 20:39:24 +01:00
|
|
|
|
2013-10-10 18:02:21 +02:00
|
|
|
try
|
|
|
|
{
|
2014-08-26 08:56:58 +02:00
|
|
|
log("Natural sleep.");
|
2014-04-26 18:21:51 +02:00
|
|
|
Thread.sleep(10000);
|
2013-10-10 18:02:21 +02:00
|
|
|
}
|
|
|
|
catch (InterruptedException e)
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2014-02-18 09:40:41 +01:00
|
|
|
|
|
|
|
_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-05 01:14:04 +02:00
|
|
|
private static void handleGroupChanges(List<DedicatedServer> dedicatedServers, HashMap<String, Entry<String, Long>> serverTracker, ServerGroup serverGroup, boolean free)
|
2014-08-01 08:37:39 +02:00
|
|
|
{
|
2014-08-14 11:10:11 +02:00
|
|
|
int serverNum = 0;
|
2014-08-05 01:14:04 +02:00
|
|
|
int requiredTotal = serverGroup.getRequiredTotalServers();
|
|
|
|
int requiredJoinable = serverGroup.getRequiredJoinableServers();
|
|
|
|
int joinableServers = serverGroup.getJoinableCount();
|
|
|
|
int totalServers = serverGroup.getServerCount();
|
|
|
|
int serversToAdd = Math.max(requiredTotal - totalServers, requiredJoinable - joinableServers);
|
|
|
|
int serversToKill = (totalServers > requiredTotal && joinableServers > requiredJoinable) ? Math.min(joinableServers - requiredJoinable, serverGroup.getEmptyServers().size()) : 0;
|
2014-08-01 08:37:39 +02:00
|
|
|
|
|
|
|
// Minimum 1500 slot bufferzone
|
2014-08-05 01:14:04 +02:00
|
|
|
if (serverGroup.getName().equalsIgnoreCase("Lobby"))
|
2014-08-01 08:37:39 +02:00
|
|
|
{
|
2014-08-18 21:46:23 +02:00
|
|
|
int availableSlots = serverGroup.getMaxPlayerCount() - serverGroup.getPlayerCount();
|
|
|
|
|
|
|
|
if (availableSlots < 1500)
|
2014-08-26 11:02:31 +02:00
|
|
|
serversToAdd = Math.max(1, (1500 - availableSlots) / serverGroup.getMaxPlayers());
|
2014-08-18 21:46:23 +02:00
|
|
|
else if (serversToKill > 0)
|
|
|
|
serversToKill = Math.min(serversToKill, (availableSlots - 1500) / 80);
|
2014-08-01 08:37:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
while (serversToAdd > 0)
|
|
|
|
{
|
2014-08-14 11:10:11 +02:00
|
|
|
serverNum = serverGroup.generateUniqueId(serverNum + 1);
|
2014-08-05 01:14:04 +02:00
|
|
|
Collections.sort(dedicatedServers, new DedicatedServerSorter());
|
|
|
|
DedicatedServer bestServer = getBestDedicatedServer(dedicatedServers, serverGroup);
|
2014-08-01 08:37:39 +02:00
|
|
|
|
|
|
|
if (bestServer == null)
|
|
|
|
{
|
2014-08-05 01:14:04 +02:00
|
|
|
System.out.println("No best dynamic server available for group " + serverGroup.getName());
|
2014-08-01 08:37:39 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-08-05 01:14:04 +02:00
|
|
|
if (serverTracker.containsKey(serverGroup.getPrefix() + "-" + serverNum))
|
|
|
|
System.out.println("[WAITING] On " + serverGroup.getPrefix() + "-" + serverNum + " to finish starting...");
|
2014-08-01 08:37:39 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
startServer(bestServer, serverGroup, serverNum, free);
|
2014-08-05 01:14:04 +02:00
|
|
|
serverTracker.put(serverGroup.getPrefix() + "-" + serverNum, new AbstractMap.SimpleEntry<String, Long>(bestServer.getPublicAddress(), System.currentTimeMillis()));
|
2014-08-01 08:37:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
serversToAdd--;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (serversToKill > 0)
|
|
|
|
{
|
2014-08-05 01:14:04 +02:00
|
|
|
List<MinecraftServer> emptyServers = new ArrayList<MinecraftServer>(serverGroup.getEmptyServers());
|
2014-08-14 11:10:11 +02:00
|
|
|
MinecraftServer emptyServer = emptyServers.get(serversToKill - 1);
|
2014-08-18 21:46:23 +02:00
|
|
|
killServer(emptyServer, "[KILLED] [EXCESS] " + emptyServer.getName() + ":" + emptyServer.getPublicAddress());
|
2014-08-01 08:37:39 +02:00
|
|
|
serversToKill--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-18 21:46:23 +02:00
|
|
|
private static void killServer(final String serverName, final String serverAddress, final String message, final boolean announce)
|
2014-02-18 09:40:41 +01:00
|
|
|
{
|
|
|
|
String cmd = "/home/mineplex/easyRemoteKillServer.sh";
|
|
|
|
|
2014-08-01 23:56:29 +02:00
|
|
|
ProcessRunner pr = new ProcessRunner(new String[] {"/bin/sh", cmd, serverAddress, serverName});
|
2014-02-18 09:40:41 +01:00
|
|
|
pr.start(new GenericRunnable<Boolean>()
|
|
|
|
{
|
|
|
|
public void run(Boolean error)
|
|
|
|
{
|
|
|
|
if (!error)
|
2014-08-01 23:56:29 +02:00
|
|
|
{
|
|
|
|
MinecraftServer server = _repository.getServerStatus(serverName);
|
|
|
|
|
|
|
|
if (server != null)
|
|
|
|
{
|
|
|
|
_repository.removeServerStatus(server);
|
|
|
|
}
|
|
|
|
}
|
2014-02-18 09:40:41 +01:00
|
|
|
|
|
|
|
if (announce)
|
|
|
|
{
|
|
|
|
if (error)
|
2014-08-26 08:56:58 +02:00
|
|
|
log("[" + serverName + ":" + serverAddress + "] Kill errored.");
|
2014-02-18 09:40:41 +01:00
|
|
|
else
|
2014-08-26 08:56:58 +02:00
|
|
|
log(message);
|
2014-02-18 09:40:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
pr.join(500);
|
|
|
|
}
|
|
|
|
catch (InterruptedException e1)
|
|
|
|
{
|
|
|
|
e1.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!pr.isDone())
|
|
|
|
_processes.add(pr);
|
|
|
|
}
|
|
|
|
|
2014-08-01 23:56:29 +02:00
|
|
|
private static boolean isServerOffline(DedicatedServer serverData)
|
2014-02-18 09:40:41 +01:00
|
|
|
{
|
|
|
|
boolean success = false;
|
|
|
|
|
|
|
|
Process process = null;
|
|
|
|
String cmd = "/home/mineplex/isServerOnline.sh";
|
|
|
|
|
2014-08-01 23:56:29 +02:00
|
|
|
ProcessBuilder processBuilder = new ProcessBuilder(new String[] {"/bin/sh", cmd, serverData.getPublicAddress()});
|
2014-02-18 09:40:41 +01:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
process = processBuilder.start();
|
|
|
|
process.waitFor();
|
|
|
|
|
|
|
|
BufferedReader reader=new BufferedReader(new InputStreamReader(process.getInputStream()));
|
|
|
|
String line = reader.readLine();
|
|
|
|
|
|
|
|
while(line != null)
|
|
|
|
{
|
|
|
|
success = line.equals("Success");
|
|
|
|
|
|
|
|
line=reader.readLine();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e1)
|
|
|
|
{
|
|
|
|
e1.printStackTrace();
|
2013-10-10 18:02:21 +02:00
|
|
|
}
|
2014-02-18 09:40:41 +01:00
|
|
|
finally
|
|
|
|
{
|
|
|
|
process.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
return !success;
|
2013-10-10 18:02:21 +02:00
|
|
|
}
|
2013-11-06 10:03:02 +01:00
|
|
|
|
2014-08-01 23:56:29 +02:00
|
|
|
private static DedicatedServer getBestDedicatedServer(Collection<DedicatedServer> dedicatedServers, ServerGroup serverGroup)
|
2013-11-06 10:03:02 +01:00
|
|
|
{
|
2014-08-01 23:56:29 +02:00
|
|
|
DedicatedServer bestServer = null;
|
2013-11-06 10:03:02 +01:00
|
|
|
|
2014-08-01 23:56:29 +02:00
|
|
|
for (DedicatedServer serverData : dedicatedServers)
|
2013-11-06 10:03:02 +01:00
|
|
|
{
|
2014-08-01 23:56:29 +02:00
|
|
|
if (serverData.getAvailableRam() > serverGroup.getRequiredRam()
|
|
|
|
&& serverData.getAvailableCpu() > serverGroup.getRequiredCpu())
|
2013-11-06 10:03:02 +01:00
|
|
|
{
|
2014-08-01 23:56:29 +02:00
|
|
|
if (bestServer == null
|
|
|
|
|| serverData.getServerCount(serverGroup) < bestServer.getServerCount(serverGroup))
|
2013-11-06 10:03:02 +01:00
|
|
|
{
|
|
|
|
bestServer = serverData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bestServer;
|
|
|
|
}
|
2014-08-01 23:56:29 +02:00
|
|
|
|
2014-08-18 21:46:23 +02:00
|
|
|
private static void killServer(final MinecraftServer serverToKill, String message)
|
2013-11-08 19:52:56 +01:00
|
|
|
{
|
2014-08-18 21:46:23 +02:00
|
|
|
killServer(serverToKill.getName(), serverToKill.getPublicAddress(), message, true);
|
2013-11-08 19:52:56 +01:00
|
|
|
}
|
|
|
|
|
2014-08-05 01:14:04 +02:00
|
|
|
private static void startServer(final DedicatedServer serverSpace, final ServerGroup serverGroup, final int serverNum, final boolean free)
|
2013-11-08 19:52:56 +01:00
|
|
|
{
|
2014-09-12 22:03:33 +02:00
|
|
|
String cmd = "/home/mineplex/easyRemoteStartServer.sh";
|
2014-08-01 23:56:29 +02:00
|
|
|
final String groupPrefix = serverGroup.getPrefix();
|
|
|
|
final String serverName = serverSpace.getName();
|
|
|
|
final String serverAddress = serverSpace.getPublicAddress();
|
2014-08-14 11:10:11 +02:00
|
|
|
|
2014-09-12 22:03:33 +02:00
|
|
|
ProcessRunner pr = new ProcessRunner(new String[] {"/bin/sh", cmd, serverAddress, serverSpace.getPrivateAddress(), (serverGroup.getPortSection() + serverNum) + "", serverGroup.getRequiredRam() + "", serverGroup.getWorldZip(), serverGroup.getPlugin(), serverGroup.getConfigPath(), serverGroup.getName(), serverGroup.getPrefix() + "-" + serverNum, serverGroup.getMinPlayers() + "", serverGroup.getMaxPlayers() + "", serverGroup.getPvp() + "", serverGroup.getTournament() + "", free + "", serverSpace.isUsRegion() ? "true" : "false", serverGroup.getArcadeGroup() + "", serverGroup.getGames(), serverGroup.getServerType(), serverGroup.getAddNoCheat() + "", serverGroup.getTeamAutoJoin() + "", serverGroup.getTeamForceBalance() + "", serverGroup.getTeamRejoin() + "", serverGroup.getGameAutoStart() + "", serverGroup.getGameTimeout() + "", serverGroup.getHotbarHubClock() + "", serverGroup.getHotbarInventory() + "", serverGroup.getPlayerKickIdle() + "", serverGroup.getRewardGems() + "", serverGroup.getRewardItems() + "", serverGroup.getRewardAchievements() + "", serverGroup.getRewardStats() + ""});
|
2014-02-18 09:40:41 +01:00
|
|
|
pr.start(new GenericRunnable<Boolean>()
|
2014-01-08 21:18:52 +01:00
|
|
|
{
|
2014-02-18 09:40:41 +01:00
|
|
|
public void run(Boolean error)
|
2014-01-08 21:18:52 +01:00
|
|
|
{
|
2014-02-18 09:40:41 +01:00
|
|
|
if (error)
|
2014-08-26 08:56:58 +02:00
|
|
|
log("[" + serverName + ":" + serverAddress + "] Errored " + serverName + "(" + groupPrefix+ "-" + serverNum + (free ? "-FREE" : "") + ")");
|
2014-02-18 09:40:41 +01:00
|
|
|
else
|
2014-08-26 08:56:58 +02:00
|
|
|
log("[" + serverName + ":" + serverAddress + "] Added " + serverName + "(" + groupPrefix+ "-" + serverNum + (free ? "-FREE" : "") + ")");
|
2014-08-05 01:14:04 +02:00
|
|
|
|
2014-01-08 21:18:52 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
pr.join(500);
|
|
|
|
}
|
|
|
|
catch (InterruptedException e1)
|
|
|
|
{
|
|
|
|
e1.printStackTrace();
|
|
|
|
}
|
|
|
|
|
2014-08-01 23:56:29 +02:00
|
|
|
serverSpace.incrementServerCount(serverGroup);
|
2014-01-08 21:18:52 +01:00
|
|
|
|
|
|
|
if (!pr.isDone())
|
|
|
|
_processes.add(pr);
|
2013-11-08 19:52:56 +01:00
|
|
|
}
|
2014-07-30 06:10:52 +02:00
|
|
|
|
|
|
|
private static void log(String message)
|
|
|
|
{
|
|
|
|
_logger.info("[" + _dateFormat.format(new Date()) + "] " + message);
|
2014-08-26 10:31:57 +02:00
|
|
|
System.out.println("[" + _dateFormat.format(new Date()) + "] " + message);
|
2014-07-30 06:10:52 +02:00
|
|
|
}
|
2013-10-10 18:02:21 +02:00
|
|
|
}
|