@rpcbase/server 0.65.0 → 0.68.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin.js +12 -9
- package/cli/build_server.js +1 -3
- package/cli/run_docker.js +18 -35
- package/cli/run_native.js +74 -28
- package/cli/start_server.js +8 -9
- package/infrastructure/mongodb/mongod.conf +9 -0
- package/infrastructure/redis/redis.conf +575 -176
- package/package.json +3 -3
- package/cli/native/get_commands.js +0 -3
package/bin.js
CHANGED
|
@@ -13,22 +13,18 @@ const run_agent = require("./cli/run_agent")
|
|
|
13
13
|
let is_command = false
|
|
14
14
|
|
|
15
15
|
const args = yargs(hideBin(process.argv))
|
|
16
|
-
.command("start", "run server/infrastructure", () => {}, (
|
|
16
|
+
.command("start", "run server/infrastructure", () => {}, (args) => {
|
|
17
17
|
is_command = true
|
|
18
|
-
start_server()
|
|
18
|
+
start_server(args)
|
|
19
19
|
})
|
|
20
|
-
.command("agent", "run the agent", () => {}, (
|
|
20
|
+
.command("agent", "run the agent", () => {}, (args) => {
|
|
21
21
|
is_command = true
|
|
22
22
|
run_agent()
|
|
23
23
|
})
|
|
24
|
-
.command("build", "build server", () => {}, (
|
|
24
|
+
.command("build", "build server", () => {}, (args) => {
|
|
25
25
|
is_command = true
|
|
26
26
|
build_server()
|
|
27
27
|
})
|
|
28
|
-
.command("ping", "ping", () => {}, (argv) => {
|
|
29
|
-
is_command = true
|
|
30
|
-
console.log("PING")
|
|
31
|
-
})
|
|
32
28
|
.option("verbose", {
|
|
33
29
|
alias: "v",
|
|
34
30
|
type: "boolean",
|
|
@@ -38,5 +34,12 @@ const args = yargs(hideBin(process.argv))
|
|
|
38
34
|
.parse()
|
|
39
35
|
|
|
40
36
|
if (!is_command) {
|
|
41
|
-
console.log("default com22mand")
|
|
37
|
+
console.log("server default com22mand")
|
|
42
38
|
}
|
|
39
|
+
|
|
40
|
+
// // add helpers to ensure proper process termination
|
|
41
|
+
// const exit_clean = () => {
|
|
42
|
+
// process.exit()
|
|
43
|
+
// }
|
|
44
|
+
// process.on("SIGINT", exit_clean) // ctrl-c
|
|
45
|
+
// process.on("SIGTERM", exit_clean) // kill
|
package/cli/build_server.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
const path = require("path")
|
|
3
3
|
const fs = require("fs")
|
|
4
4
|
|
|
5
|
-
const get_runtime = require("./get_runtime")
|
|
6
5
|
const run_docker = require("./run_docker")
|
|
7
6
|
const run_native = require("./run_native")
|
|
8
7
|
|
|
@@ -11,11 +10,10 @@ const build_server = async() => {
|
|
|
11
10
|
// const build_schemas =
|
|
12
11
|
// const infrastructure_dir = path.join(process.cwd(), "../infrastructure")
|
|
13
12
|
//
|
|
14
|
-
//
|
|
13
|
+
// prefix
|
|
15
14
|
// const proj_parent_dir = path.join(infrastructure_dir, "../../")
|
|
16
15
|
// const proj_prefix = path.basename(proj_parent_dir)
|
|
17
16
|
//
|
|
18
|
-
// const runtime = get_runtime()
|
|
19
17
|
//
|
|
20
18
|
// if (runtime === "native") {
|
|
21
19
|
// run_native(infrastructure_dir, proj_prefix)
|
package/cli/run_docker.js
CHANGED
|
@@ -1,61 +1,44 @@
|
|
|
1
1
|
/* @flow */
|
|
2
|
-
const {
|
|
2
|
+
const {execSync} = require("child_process")
|
|
3
3
|
const path = require("path")
|
|
4
|
+
const fs = require("fs")
|
|
4
5
|
|
|
5
6
|
const chalk = require("chalk")
|
|
6
7
|
|
|
7
8
|
const is_production = "yes" === process.env.INFRASTRUCTURE_IS_PRODUCTION
|
|
8
9
|
|
|
9
|
-
const run_docker = async(infrastructure_dir, proj_prefix
|
|
10
|
+
const run_docker = async(infrastructure_dir, proj_prefix) => {
|
|
10
11
|
// env
|
|
11
12
|
const env_path = path.relative(infrastructure_dir, path.join(process.cwd(), "./.env"))
|
|
12
13
|
|
|
14
|
+
const exists = (f) => {
|
|
15
|
+
const target_path = path.join(infrastructure_dir, f)
|
|
16
|
+
return fs.existsSync(target_path)
|
|
17
|
+
}
|
|
18
|
+
|
|
13
19
|
// compose files
|
|
14
20
|
const compose_files = ["-f", "common.yml"]
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (is_production) {
|
|
21
|
+
// TODO: which files are loaded and when should be documented
|
|
22
|
+
// when running with native mode, do not load native infrastructure
|
|
23
|
+
if (is_production && exists("prod.yml")) {
|
|
19
24
|
compose_files.push("-f", "prod.yml")
|
|
20
25
|
}
|
|
21
|
-
|
|
26
|
+
if (!is_production && exists("dev.yml")) {
|
|
27
|
+
compose_files.push("-f", "dev.yml")
|
|
28
|
+
}
|
|
22
29
|
|
|
23
30
|
const opts = ["--build", "--remove-orphans"]
|
|
24
31
|
if (!is_production) opts.push("--abort-on-container-exit")
|
|
25
32
|
|
|
26
33
|
const cmd = "docker-compose"
|
|
27
|
-
// const cmd_args = `--env-file ${env_path} -p ${proj_prefix} ${compose_files.join(" ")} up ${opts.join(" ")}`
|
|
28
34
|
const cmd_args = ["--env-file", env_path, "-p", proj_prefix, ...compose_files, "up", ...opts]
|
|
29
35
|
|
|
30
36
|
console.log(cmd_args.join(" "))
|
|
31
37
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (line.trim() === "") {
|
|
37
|
-
return
|
|
38
|
-
}
|
|
39
|
-
process.stdout.write(`${chalk.cyan("docker")}: ${line}\n`)
|
|
40
|
-
})
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
ps.stderr.on("data", (data) => {
|
|
44
|
-
const lines = data.toString().split("\n")
|
|
45
|
-
lines.forEach((line) => {
|
|
46
|
-
if (line.trim() === "") {
|
|
47
|
-
return
|
|
48
|
-
}
|
|
49
|
-
process.stdout.write(`${chalk.cyan("docker")}: ${chalk.yellow(line)}\n`)
|
|
50
|
-
})
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
// try {
|
|
54
|
-
//
|
|
55
|
-
// } catch (err) {
|
|
56
|
-
// console.log("start_server::error\n", err)
|
|
57
|
-
// process.exit(1)
|
|
58
|
-
// }
|
|
38
|
+
// WARNING: blocks the process
|
|
39
|
+
// this is the only way to have docker-compose shut down gracefully
|
|
40
|
+
execSync(`${cmd} ${cmd_args.join(" ")}`, {cwd: infrastructure_dir, stdio: "inherit"})
|
|
41
|
+
|
|
59
42
|
}
|
|
60
43
|
|
|
61
44
|
module.exports = run_docker
|
package/cli/run_native.js
CHANGED
|
@@ -1,46 +1,92 @@
|
|
|
1
1
|
/* @flow */
|
|
2
2
|
const {spawn} = require("child_process")
|
|
3
|
-
// const dotenv = require("dotenv")
|
|
4
3
|
const path = require("path")
|
|
5
4
|
const fs = require("fs")
|
|
6
5
|
|
|
6
|
+
const dotenv = require("dotenv")
|
|
7
|
+
const mkdirp = require("mkdirp")
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// ["mongod", [
|
|
11
|
-
// "--quiet",
|
|
12
|
-
// "--port", "$DATABASE_PORT_0",
|
|
13
|
-
// "--replSet", "rs0",
|
|
14
|
-
// "--logpath", "/var/log/logs.txt",
|
|
15
|
-
// ]],
|
|
16
|
-
// ["mongod", [
|
|
17
|
-
// "--quiet",
|
|
18
|
-
// "--port", "$DATABASE_PORT_2",
|
|
19
|
-
// "--replSet", "rs0",
|
|
20
|
-
// "--logpath", "/var/log/logs.txt",
|
|
21
|
-
// ]],
|
|
22
|
-
]
|
|
23
|
-
|
|
24
|
-
// const get_env = () => {
|
|
25
|
-
// const env_path = path.join(process.cwd(), ".env")
|
|
26
|
-
// const env_buf = fs.readFileSync(env_path)
|
|
27
|
-
// const env = dotenv.parse(env_buf)
|
|
28
|
-
// return env
|
|
29
|
-
// }
|
|
9
|
+
// TODO: verify mongod and redis-sever executables are present
|
|
10
|
+
// and have the right version
|
|
30
11
|
|
|
12
|
+
// "redis-server", "/usr/local/etc/redis/redis.conf", "--port", $WORKER_QUEUE_PORT
|
|
13
|
+
|
|
14
|
+
// load env
|
|
15
|
+
const get_env = () => {
|
|
16
|
+
const env_path = path.join(process.cwd(), "./.env")
|
|
17
|
+
const env_buf = fs.readFileSync(env_path)
|
|
18
|
+
const env = dotenv.parse(env_buf)
|
|
19
|
+
return env
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const init_processes = () => {
|
|
23
|
+
const env = get_env()
|
|
24
|
+
|
|
25
|
+
const infrastructure_conf_dir = path.join(__dirname, "../infrastructure")
|
|
26
|
+
|
|
27
|
+
// create data dirs
|
|
28
|
+
const db_path = path.join(process.cwd(), "../infrastructure/data/database/db/")
|
|
29
|
+
if (!fs.existsSync(db_path)) {
|
|
30
|
+
mkdirp.sync(db_path)
|
|
31
|
+
}
|
|
32
|
+
const db_logs_path = path.join(process.cwd(), "../infrastructure/data/database/log/")
|
|
33
|
+
if (!fs.existsSync(db_logs_path)) {
|
|
34
|
+
mkdirp.sync(db_logs_path)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
const processes = [
|
|
39
|
+
// web server
|
|
40
|
+
// TODO: do not use yarn dev server command
|
|
41
|
+
{name: "server", cmd: ["yarn", ["dev"]]},
|
|
42
|
+
// mongodb database
|
|
43
|
+
{name: "database", cmd: ["mongod", [
|
|
44
|
+
"--quiet",
|
|
45
|
+
"--dbpath", db_path,
|
|
46
|
+
"--port", env.DATABASE_PORT,
|
|
47
|
+
// "--bind_ip_all",
|
|
48
|
+
// "--logpath", "/var/log/logs.txt",
|
|
49
|
+
"--replSet", "rs0"
|
|
50
|
+
]]},
|
|
51
|
+
{name: "session-store", cmd: ["redis-server", [
|
|
52
|
+
path.join(infrastructure_conf_dir, "./redis/redis.conf"),
|
|
53
|
+
"--port", env.SESSION_STORE_PORT,
|
|
54
|
+
]]},
|
|
55
|
+
|
|
56
|
+
// redis worker-queue
|
|
57
|
+
// redis session-store
|
|
58
|
+
// TODO: add a redis cache
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
return processes
|
|
62
|
+
}
|
|
31
63
|
|
|
32
64
|
// TODO: run each native process from list
|
|
33
65
|
// TODO: handle process close
|
|
34
66
|
const run_native = (infrastructure_dir, proj_prefix) => {
|
|
35
67
|
console.log("running in NATIVE mode")
|
|
36
|
-
// const env = get_env()
|
|
37
68
|
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
69
|
+
const processes = init_processes()
|
|
70
|
+
|
|
71
|
+
const run_process = (item) => {
|
|
72
|
+
// console.log("start process", item)
|
|
73
|
+
const ps = spawn(item.cmd[0], item.cmd[1], {env: {...process.env, CONTAINER_MODE: "native"}})
|
|
42
74
|
|
|
75
|
+
ps.stdout.on("data", (data) => {
|
|
76
|
+
process.stdout.write(`${item.name}: ${data.toString()}`)
|
|
77
|
+
})
|
|
43
78
|
|
|
79
|
+
ps.stderr.on("data", (data) => {
|
|
80
|
+
process.stderr.write(`${item.name}: ${data.toString()}`)
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const spawned = processes.map(run_process)
|
|
85
|
+
|
|
86
|
+
process.on("exit", () => {
|
|
87
|
+
console.log("EXIT from native1")
|
|
88
|
+
// ps.kill()
|
|
89
|
+
})
|
|
44
90
|
}
|
|
45
91
|
|
|
46
92
|
module.exports = run_native
|
package/cli/start_server.js
CHANGED
|
@@ -2,30 +2,29 @@
|
|
|
2
2
|
const path = require("path")
|
|
3
3
|
const fs = require("fs")
|
|
4
4
|
|
|
5
|
-
const get_runtime = require("./get_runtime")
|
|
6
5
|
const run_docker = require("./run_docker")
|
|
7
6
|
const run_native = require("./run_native")
|
|
8
|
-
|
|
7
|
+
const get_runtime = require("./get_runtime")
|
|
9
8
|
|
|
10
9
|
// TODO: auto create network if necessary
|
|
11
10
|
// docker network create local-network
|
|
12
11
|
|
|
13
|
-
const start_server = async() => {
|
|
12
|
+
const start_server = async(args) => {
|
|
14
13
|
const infrastructure_dir = path.join(process.cwd(), "../infrastructure")
|
|
15
14
|
|
|
15
|
+
const runtime = get_runtime()
|
|
16
|
+
|
|
16
17
|
// prefix
|
|
17
18
|
const proj_parent_dir = path.join(infrastructure_dir, "../../")
|
|
18
19
|
const proj_prefix = path.basename(proj_parent_dir)
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (runtime === "native") {
|
|
23
|
-
run_docker(infrastructure_dir, proj_prefix, true)
|
|
21
|
+
if (runtime === "docker") {
|
|
22
|
+
run_docker(infrastructure_dir, proj_prefix)
|
|
23
|
+
} else if (runtime === "native") {
|
|
24
24
|
run_native(infrastructure_dir, proj_prefix)
|
|
25
25
|
} else {
|
|
26
|
-
|
|
26
|
+
throw new Error("unknown runtime")
|
|
27
27
|
}
|
|
28
|
-
|
|
29
28
|
}
|
|
30
29
|
|
|
31
30
|
module.exports = start_server
|