@rpcbase/server 0.306.0 → 0.308.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/cli/run_native.js +12 -2
- package/database.js +26 -8
- package/package.json +1 -1
package/cli/run_native.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* @flow */
|
|
2
|
+
const assert = require("assert")
|
|
2
3
|
const {spawn} = require("child_process")
|
|
3
4
|
const path = require("path")
|
|
4
5
|
const fs = require("fs")
|
|
@@ -13,6 +14,7 @@ const mkdirp = require("mkdirp")
|
|
|
13
14
|
|
|
14
15
|
const is_production = process.env.NODE_ENV === "production"
|
|
15
16
|
|
|
17
|
+
|
|
16
18
|
const NO_PRINT_LIST = [
|
|
17
19
|
// "database",
|
|
18
20
|
]
|
|
@@ -28,6 +30,8 @@ const get_env = () => {
|
|
|
28
30
|
const get_processes = (args) => {
|
|
29
31
|
const env = get_env()
|
|
30
32
|
|
|
33
|
+
assert(env.RB_APP_NAME, "missing RB_APP_NAME in env")
|
|
34
|
+
|
|
31
35
|
const infrastructure_conf_dir = path.join(__dirname, "../infrastructure")
|
|
32
36
|
|
|
33
37
|
// db storage
|
|
@@ -42,7 +46,12 @@ const get_processes = (args) => {
|
|
|
42
46
|
const worker_queue_dir = path.join(process.cwd(), "../infrastructure/data/worker-queue/data")
|
|
43
47
|
const worker_queue_logs_path = path.join(process.cwd(), "../infrastructure/data/worker-queue/log/logs.txt")
|
|
44
48
|
|
|
45
|
-
|
|
49
|
+
const has_uds = true
|
|
50
|
+
const uds_root_path = `/tmp/${env.RB_APP_NAME}/`
|
|
51
|
+
if (has_uds && !fs.existsSync(uds_root_path)) {
|
|
52
|
+
mkdirp.sync(uds_root_path)
|
|
53
|
+
}
|
|
54
|
+
|
|
46
55
|
const processes = [
|
|
47
56
|
// web server
|
|
48
57
|
{
|
|
@@ -66,8 +75,9 @@ const get_processes = (args) => {
|
|
|
66
75
|
cmd: ["mongod", [
|
|
67
76
|
"--quiet",
|
|
68
77
|
"--dbpath", db_path,
|
|
78
|
+
"--bind_ip", "127.0.0.1", // TODO: bind to 0.0.0.0 here when going multinodes
|
|
69
79
|
"--port", env.DATABASE_PORT,
|
|
70
|
-
|
|
80
|
+
...(has_uds ? ["--unixSocketPrefix", uds_root_path, "--filePermissions", "0700"] : []),
|
|
71
81
|
// if in verbose mode, print to stdout, else write to file
|
|
72
82
|
...(args.verbose ? [] : ["--logpath", db_logs_path]),
|
|
73
83
|
"--replSet", "rs0"
|
package/database.js
CHANGED
|
@@ -13,7 +13,7 @@ require("./src/models/Invite")
|
|
|
13
13
|
require("./src/models/ResetPasswordToken")
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
const {
|
|
16
|
+
const {RB_APP_NAME, DATABASE_PORT} = process.env
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
// database can be set by env variable or passed as paramaters to
|
|
@@ -22,16 +22,32 @@ if (typeof DATABASE_PORT !== "string" || !isPort(DATABASE_PORT)) {
|
|
|
22
22
|
throw new Error("expected DATABASE_PORT to be a valid port number")
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
if (typeof
|
|
26
|
-
throw new Error("expected
|
|
25
|
+
if (typeof RB_APP_NAME !== "string") {
|
|
26
|
+
throw new Error("expected RB_APP_NAME in env to be a string")
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
const hostname = is_docker() ? "database" : "127.0.0.1"
|
|
30
29
|
|
|
31
|
-
const
|
|
30
|
+
const get_mongo_url = () => {
|
|
31
|
+
const conn_suffix = `?directConnection=true&replicaSet=rs0`
|
|
32
32
|
|
|
33
|
+
let url
|
|
33
34
|
|
|
34
|
-
//
|
|
35
|
+
// connect via tcp in docker
|
|
36
|
+
if (is_docker()) {
|
|
37
|
+
const hostname = "database" // "127.0.0.1"
|
|
38
|
+
url = `mongodb://${hostname}:${DATABASE_PORT}/${conn_suffix}`
|
|
39
|
+
}
|
|
40
|
+
// when running natively, prefer the unix socket
|
|
41
|
+
else {
|
|
42
|
+
const uds_root_path = `/tmp/sockets-${RB_APP_NAME}/`
|
|
43
|
+
url = `mongodb://${encodeURIComponent(uds_root_path)}mongodb-${DATABASE_PORT}.sock`
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return url
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
// TODO: handle multiple databases, remove RB_APP_NAME env ??
|
|
35
51
|
module.exports = async(...database_names) => {
|
|
36
52
|
// set listeners before attempting to connect
|
|
37
53
|
mongoose.connection.on("connected", () => {
|
|
@@ -49,13 +65,15 @@ module.exports = async(...database_names) => {
|
|
|
49
65
|
console.log("mongoose connection error", err)
|
|
50
66
|
})
|
|
51
67
|
|
|
68
|
+
const mongo_url = get_mongo_url()
|
|
52
69
|
console.log("connect mongo_url", mongo_url)
|
|
53
70
|
|
|
54
71
|
const connect_opts = {
|
|
55
|
-
|
|
72
|
+
dbName: RB_APP_NAME,
|
|
73
|
+
minPoolSize: 8,
|
|
56
74
|
// maxPoolSize: 1024 * 1024,
|
|
57
75
|
// TODO: setting this to a low value adds ~3s delay to requests... WHY
|
|
58
|
-
maxPoolSize:
|
|
76
|
+
maxPoolSize: 512,
|
|
59
77
|
family: 4, // force ipv4
|
|
60
78
|
driverInfo: {
|
|
61
79
|
name: `${pack.name}/database`,
|