Skip to content

Commit

Permalink
added screen service type
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoMarlir committed May 24, 2024
1 parent 642fc23 commit ff52a36
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ abstract class AbstractServiceProcess {

abstract fun start(
service: ICloudService,
command: String
command: MutableList<String>
)

abstract fun stop()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package me.blueamethyst.bluecloud.runner

import me.blueamethyst.bluecloud.runner.jvm.JvmServiceProcess
import me.blueamethyst.bluecloud.runner.impl.JvmServiceProcess
import kotlin.reflect.KClass

class ProcessRegistry {
private val processes = mutableMapOf<String, KClass<out AbstractServiceProcess>>(
"jvm" to JvmServiceProcess::class
"jvm" to JvmServiceProcess::class,
"screen" to JvmServiceProcess::class
)

fun registerServiceProcess(name: String, process: KClass<out AbstractServiceProcess>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.blueamethyst.bluecloud.runner.jvm
package me.blueamethyst.bluecloud.runner.impl

import me.blueamethyst.bluecloud.api.service.ICloudService
import me.blueamethyst.bluecloud.runner.AbstractServiceProcess
Expand All @@ -10,7 +10,7 @@ class JvmServiceProcess: AbstractServiceProcess() {

lateinit var process: Process; private set
lateinit var directory: File; private set
lateinit var startCommand: String; private set
lateinit var startCommand: MutableList<String>; private set

/*
override fun start(
Expand All @@ -25,7 +25,7 @@ class JvmServiceProcess: AbstractServiceProcess() {
}
*/

override fun start(service: ICloudService, command: String) {
override fun start(service: ICloudService, command: MutableList<String>) {
startCommand = command
createProcess()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package me.blueamethyst.bluecloud.runner.impl.screen

import java.nio.file.Path

class UnixScreen(
val name: String,
val command: MutableList<String>,
) {

fun create(): ProcessBuilder {
return ProcessBuilder(buildCommand())
}

private fun buildCommand(): MutableList<String> {
return buildList {
add("screen")
add("-dmS")
add(name)
addAll(command)
}.toMutableList()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package me.blueamethyst.bluecloud.runner.impl.screen

import me.blueamethyst.bluecloud.api.service.ICloudService
import me.blueamethyst.bluecloud.runner.AbstractServiceProcess

class UnixScreenServiceProcess: AbstractServiceProcess() {
lateinit var unixScreen: UnixScreen; private set
lateinit var process: Process; private set

override fun start(service: ICloudService, command: MutableList<String>) {
unixScreen = UnixScreen("bluecloud-${service.getId()}", command)
process = unixScreen.create().start()
}

override fun stop() {
process.destroy()
}

override fun kill() {
process.destroy()
}
}

0 comments on commit ff52a36

Please sign in to comment.