Fix weird stopping behaviour
Dieser Commit ist enthalten in:
Ursprung
79c29eb8c0
Commit
91a0fabde9
45
build.gradle
45
build.gradle
@ -93,13 +93,14 @@ task finalizeProject {
|
|||||||
build.finalizedBy(finalizeProject)
|
build.finalizedBy(finalizeProject)
|
||||||
|
|
||||||
if (project.hasProperty("hostname")) {
|
if (project.hasProperty("hostname")) {
|
||||||
|
def server = "Dev1.15"
|
||||||
|
// def server = "Developer"
|
||||||
|
|
||||||
task uploadProject {
|
task uploadProject {
|
||||||
description 'Upload this project'
|
description 'Upload this project'
|
||||||
group "Steamwar"
|
group "Steamwar"
|
||||||
|
|
||||||
doLast {
|
doLast {
|
||||||
def server = "Dev1.15"
|
|
||||||
// def server = "Developer"
|
|
||||||
await(shell("scp ${libs}/${jarName} ${hostname}:~/${server}/plugins"))
|
await(shell("scp ${libs}/${jarName} ${hostname}:~/${server}/plugins"))
|
||||||
if (!answer("Start ${server} server?")) {
|
if (!answer("Start ${server} server?")) {
|
||||||
return
|
return
|
||||||
@ -107,6 +108,15 @@ if (project.hasProperty("hostname")) {
|
|||||||
serverStart(server)
|
serverStart(server)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
task startDevServer {
|
||||||
|
description 'Start the DevServer'
|
||||||
|
group "Steamwar"
|
||||||
|
|
||||||
|
doLast {
|
||||||
|
serverStart(server)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def await(Process proc) {
|
def await(Process proc) {
|
||||||
@ -127,12 +137,32 @@ def shell(String command) {
|
|||||||
def serverStart(String serverName) {
|
def serverStart(String serverName) {
|
||||||
def proc = shell("ssh -t ${hostname} \"./mc ${serverName}\"")
|
def proc = shell("ssh -t ${hostname} \"./mc ${serverName}\"")
|
||||||
|
|
||||||
Thread outputThread = proc.consumeProcessOutputStream(System.out)
|
Thread outputThread = new Thread({
|
||||||
|
Reader reader = proc.getInputStream().newReader();
|
||||||
|
Writer writer = System.out.newWriter();
|
||||||
|
try {
|
||||||
|
while (proc.alive) {
|
||||||
|
String s = reader.readLine()
|
||||||
|
if (s == null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (s.contains("SteamWar? Unbekannter Befehl.")) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
writer.write(s + "\n")
|
||||||
|
writer.flush()
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
// Ignored
|
||||||
|
}
|
||||||
|
})
|
||||||
outputThread.setName("${serverName} - OutputThread")
|
outputThread.setName("${serverName} - OutputThread")
|
||||||
|
outputThread.start()
|
||||||
|
|
||||||
|
Writer writer
|
||||||
Thread inputThread = new Thread({
|
Thread inputThread = new Thread({
|
||||||
Reader reader = System.in.newReader()
|
Reader reader = System.in.newReader()
|
||||||
Writer writer = proc.getOutputStream().newWriter()
|
writer = proc.getOutputStream().newWriter()
|
||||||
try {
|
try {
|
||||||
while (proc.alive) {
|
while (proc.alive) {
|
||||||
String s = reader.readLine()
|
String s = reader.readLine()
|
||||||
@ -150,11 +180,14 @@ def serverStart(String serverName) {
|
|||||||
if (!proc.alive) {
|
if (!proc.alive) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
Writer writer = proc.getOutputStream().newWriter()
|
writer = proc.getOutputStream().newWriter()
|
||||||
writer.write("stop\n")
|
writer.write("stop\n")
|
||||||
writer.flush()
|
writer.flush()
|
||||||
|
|
||||||
proc.getInputStream().close()
|
while (proc.alive) {
|
||||||
|
Thread.sleep(10)
|
||||||
|
}
|
||||||
|
proc.closeStreams()
|
||||||
outputThread.interrupt()
|
outputThread.interrupt()
|
||||||
inputThread.interrupt()
|
inputThread.interrupt()
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren