This repository was archived by the owner on Jun 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.main.kts
More file actions
53 lines (49 loc) · 1.64 KB
/
deploy.main.kts
File metadata and controls
53 lines (49 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
@file:Repository("https://repo.maven.apache.org/maven2/")
@file:DependsOn("com.jcraft:jsch:0.1.55")
import com.jcraft.jsch.ChannelExec
import com.jcraft.jsch.ChannelSftp
import com.jcraft.jsch.JSch
import java.io.File
val jsch = JSch()
jsch.addIdentity("node01-ssh-key", System.getenv("NODE01_SSH_KEY").toByteArray(), null, null)
val session = jsch.getSession(
System.getenv("NODE_01_USER").toString(),
System.getenv("NODE_01_HOSTNAME").toString(),
System.getenv("NODE_01_PORT").toInt()
).apply {
setConfig("StrictHostKeyChecking", "no")
connect()
}
val sftp = session.openChannel("sftp").apply {
connect()
} as ChannelSftp
fun deploy(from: String, to: String) =
sftp.put(from, to, ChannelSftp.OVERWRITE)
fun Deploy_main.runCommandSync(it: String) {
(session.openChannel("exec") as ChannelExec).apply {
setCommand(it)
connect()
while (!isClosed) {
Thread.sleep(100)
}
if (exitStatus != 0) {
throw RuntimeException(
"Failed to run command \"${it}\": ${
inputStream.readAllBytes().decodeToString()
}"
)
}
}
}
val files = listOf(
"discord/build/libs/discord.jar" to "/home/core/modules/discord.jar",
"discord/build/libs/monitor.jar" to "/home/core/modules/monitor.jar",
)
runCommandSync("service core-standalone stop")
files.forEach {
runCommandSync("mkdir -p ${it.second.substringBeforeLast("/")}")
deploy(File(it.first).absolutePath.also { s -> println("Deploying $s to ${it.second}")}, it.second)
}
sftp.disconnect()
runCommandSync("service core-standalone start")
session.disconnect()