Zond: скрипт перед запуском сервера
This commit is contained in:
@@ -14,7 +14,12 @@ import org.apache.commons.exec.ExecuteWatchdog;
|
|||||||
import org.apache.commons.exec.Executor;
|
import org.apache.commons.exec.Executor;
|
||||||
import org.fusesource.jansi.Ansi;
|
import org.fusesource.jansi.Ansi;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ZondCommandHandler implements CommandHandler {
|
public class ZondCommandHandler implements CommandHandler {
|
||||||
private Executor executor;
|
private Executor executor;
|
||||||
@@ -57,6 +62,27 @@ public class ZondCommandHandler implements CommandHandler {
|
|||||||
}, "Thread Ticker");
|
}, "Thread Ticker");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void preStartScript() {
|
||||||
|
if (Config.getInstance().getString("cmd.prestart").isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
ProcessBuilder builder = new ProcessBuilder(Arrays.asList(
|
||||||
|
Config.getInstance().getString("cmd.prestart").split(" ", 2)));
|
||||||
|
builder.redirectErrorStream(true);
|
||||||
|
try {
|
||||||
|
Process process = builder.start();
|
||||||
|
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null) {
|
||||||
|
Shell.getInstance().getOutput().println(zondColored(line));
|
||||||
|
}
|
||||||
|
process.waitFor();
|
||||||
|
} catch (IOException | InterruptedException e) {
|
||||||
|
Shell.getInstance().getOutput()
|
||||||
|
.println(zondColored("[!] PreStart error: " + e.getMessage(), Ansi.Color.RED));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(String commandLine) {
|
public void handle(String commandLine) {
|
||||||
if (commandLine.startsWith(":")) {
|
if (commandLine.startsWith(":")) {
|
||||||
@@ -103,6 +129,8 @@ public class ZondCommandHandler implements CommandHandler {
|
|||||||
|
|
||||||
private void startProcess() {
|
private void startProcess() {
|
||||||
if (watchdog == null || !watchdog.isWatching()) {
|
if (watchdog == null || !watchdog.isWatching()) {
|
||||||
|
preStartScript();
|
||||||
|
|
||||||
if (watchdog == null) {
|
if (watchdog == null) {
|
||||||
watchdog = new ZondExecuteWatchdog(
|
watchdog = new ZondExecuteWatchdog(
|
||||||
ExecuteWatchdog.INFINITE_TIMEOUT,
|
ExecuteWatchdog.INFINITE_TIMEOUT,
|
||||||
|
|||||||
@@ -11,3 +11,4 @@ pingmonitor.maxlost = 6
|
|||||||
#Linux
|
#Linux
|
||||||
cmd.killer = kill -KILL %PID
|
cmd.killer = kill -KILL %PID
|
||||||
cmd.start = java -jar server.jar
|
cmd.start = java -jar server.jar
|
||||||
|
cmd.prestart = echo Hello
|
||||||
Reference in New Issue
Block a user