blob: 5116d63f179c0decdc762cb6d801e1abc6a91764 (
plain)
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
|
package org.pacien.tincapp.commands
import org.pacien.tincapp.context.AppPaths
import java.io.IOException
/**
* @author pacien
*/
object Tinc {
private fun newCommand(netConf: AppPaths.NetConf): Command =
Command(AppPaths.tinc().absolutePath)
.withOption("config", AppPaths.confDir(netConf).absolutePath)
.withOption("pidfile", AppPaths.pidFile(netConf).absolutePath)
// independently runnable commands
@Throws(IOException::class)
fun fsck(netConf: AppPaths.NetConf, fix: Boolean): List<String> {
var cmd = newCommand(netConf).withArguments("fsck")
if (fix) cmd = cmd.withOption("force")
return Executor.call(cmd)
}
// commands requiring a running tinc daemon
@Throws(IOException::class)
fun stop(netConf: AppPaths.NetConf) {
Executor.call(newCommand(netConf).withArguments("stop"))
}
@Throws(IOException::class)
fun dumpNodes(netConf: AppPaths.NetConf, reachable: Boolean): List<String> =
Executor.call(
if (reachable) newCommand(netConf).withArguments("dump", "reachable", "nodes")
else newCommand(netConf).withArguments("dump", "nodes"))
@Throws(IOException::class)
fun info(netConf: AppPaths.NetConf, node: String): String =
Executor.call(newCommand(netConf).withArguments("info", node)).joinToString("\n")
}
|