Skip to content

Commit 73ce45f

Browse files
authored
Merge pull request #32 from simplecloudapp/fix/screen-executor
fix: ScreenExecutor
2 parents 656039d + 79dfa49 commit 73ce45f

File tree

9 files changed

+44
-12
lines changed

9 files changed

+44
-12
lines changed

serverhost-runtime/src/main/kotlin/app/simplecloud/droplet/serverhost/runtime/runner/DefaultServerEnvironment.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import app.simplecloud.droplet.serverhost.runtime.config.environment.Environment
77
import app.simplecloud.droplet.serverhost.runtime.config.environment.EnvironmentConfigRepository
88
import app.simplecloud.droplet.serverhost.runtime.host.ServerVersionLoader
99
import app.simplecloud.droplet.serverhost.runtime.launcher.ServerHostStartCommand
10-
import app.simplecloud.droplet.serverhost.runtime.process.ProcessFinder
10+
import app.simplecloud.droplet.serverhost.shared.process.ProcessFinder
1111
import app.simplecloud.droplet.serverhost.runtime.template.TemplateProvider
1212
import app.simplecloud.droplet.serverhost.runtime.util.JarMainClass
1313
import app.simplecloud.droplet.serverhost.runtime.util.ScreenCapabilities
@@ -341,6 +341,7 @@ class DefaultServerEnvironment(
341341
val process = getProcess(server.uniqueId)
342342
?: return false
343343
val streamer = ScreenCommandExecutor(process.pid())
344+
if(!streamer.isScreen()) return false
344345
streamer.sendCommand(command)
345346
return true
346347
}

serverhost-runtime/src/main/kotlin/app/simplecloud/droplet/serverhost/runtime/runner/MetricsTracker.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package app.simplecloud.droplet.serverhost.runtime.runner
33
import app.simplecloud.controller.shared.server.Server
44
import app.simplecloud.droplet.api.metrics.MetricsEventNames
55
import app.simplecloud.droplet.api.time.ProtobufTimestamp
6-
import app.simplecloud.droplet.serverhost.runtime.process.ProcessInfo
6+
import app.simplecloud.droplet.serverhost.shared.process.ProcessInfo
77
import app.simplecloud.pubsub.PubSubClient
88
import build.buf.gen.simplecloud.metrics.v1.Metric
99
import build.buf.gen.simplecloud.metrics.v1.MetricMeta

serverhost-shared/src/main/kotlin/app/simplecloud/droplet/serverhost/shared/hack/ScreenExecutor.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package app.simplecloud.droplet.serverhost.shared.hack
22

3+
import app.simplecloud.droplet.serverhost.shared.process.ProcessInfo
4+
35
class ScreenExecutor(private var pid: Long) {
6+
47
private var isScreen = false
58

69
init {
710
var handle = ProcessHandle.of(pid)
811
while (handle.isPresent) {
9-
if (handle.get().info().commandLine().orElseGet { "" }.lowercase().startsWith("screen") || handle.get()
10-
.info().command().orElseGet { "" }.lowercase().startsWith("screen") || handle.get().info()
11-
.arguments().orElseGet { arrayOf("none") }.firstOrNull()?.lowercase()?.startsWith("screen") == true
12-
) {
12+
if (ProcessInfo.of(handle.get()).getCommand().lowercase().startsWith("screen")) {
1313
pid = handle.get().pid()
1414
isScreen = true
1515
break

serverhost-runtime/src/main/kotlin/app/simplecloud/droplet/serverhost/runtime/process/MacProcessInfo.kt renamed to serverhost-shared/src/main/kotlin/app/simplecloud/droplet/serverhost/shared/process/MacProcessInfo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package app.simplecloud.droplet.serverhost.runtime.process
1+
package app.simplecloud.droplet.serverhost.shared.process
22

33
class MacProcessInfo(private val pid: Long) : ProcessInfo {
44
override fun getCommand(): String {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package app.simplecloud.droplet.serverhost.shared.process
2+
3+
import app.simplecloud.droplet.serverhost.shared.hack.OS
4+
import java.nio.file.Files
5+
import java.nio.file.Path
6+
import java.nio.file.Paths
7+
import java.util.*
8+
9+
object ProcessDirectory {
10+
11+
fun of(handle: ProcessHandle): Optional<Path> {
12+
val os = OS.get() ?: return Optional.empty()
13+
return when (os) {
14+
OS.LINUX, OS.MAC -> {
15+
ofUnix(handle.pid())
16+
}
17+
OS.WINDOWS -> {
18+
//TODO: Add native code (or leave as is, will still work on windows)
19+
Optional.empty()
20+
}
21+
}
22+
}
23+
24+
private fun ofUnix(pid: Long): Optional<Path> {
25+
val path = Paths.get("/proc", pid.toString(), "cwd")
26+
return try {
27+
Optional.of(Files.readSymbolicLink(path))
28+
}catch (e: Exception) {
29+
Optional.empty()
30+
}
31+
}
32+
}

serverhost-runtime/src/main/kotlin/app/simplecloud/droplet/serverhost/runtime/process/ProcessFinder.kt renamed to serverhost-shared/src/main/kotlin/app/simplecloud/droplet/serverhost/shared/process/ProcessFinder.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
package app.simplecloud.droplet.serverhost.runtime.process
1+
package app.simplecloud.droplet.serverhost.shared.process
22

3-
import app.simplecloud.droplet.serverhost.runtime.util.ProcessDirectory
43
import java.nio.file.Path
54
import java.util.*
65
import kotlin.io.path.absolutePathString

serverhost-runtime/src/main/kotlin/app/simplecloud/droplet/serverhost/runtime/process/ProcessInfo.kt renamed to serverhost-shared/src/main/kotlin/app/simplecloud/droplet/serverhost/shared/process/ProcessInfo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package app.simplecloud.droplet.serverhost.runtime.process
1+
package app.simplecloud.droplet.serverhost.shared.process
22

33
import app.simplecloud.droplet.serverhost.shared.hack.OS
44
import app.simplecloud.droplet.serverhost.shared.hack.PortProcessHandle

serverhost-runtime/src/main/kotlin/app/simplecloud/droplet/serverhost/runtime/process/UnixProcessInfo.kt renamed to serverhost-shared/src/main/kotlin/app/simplecloud/droplet/serverhost/shared/process/UnixProcessInfo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package app.simplecloud.droplet.serverhost.runtime.process
1+
package app.simplecloud.droplet.serverhost.shared.process
22

33
class UnixProcessInfo(private val pid: Long) : ProcessInfo {
44
override fun getCommand(): String {

serverhost-runtime/src/main/kotlin/app/simplecloud/droplet/serverhost/runtime/process/WindowsProcessInfo.kt renamed to serverhost-shared/src/main/kotlin/app/simplecloud/droplet/serverhost/shared/process/WindowsProcessInfo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package app.simplecloud.droplet.serverhost.runtime.process
1+
package app.simplecloud.droplet.serverhost.shared.process
22

33
class WindowsProcessInfo(private val pid: Long) : ProcessInfo {
44
override fun getCommand(): String {

0 commit comments

Comments
 (0)