@rpcbase/server 0.70.0 → 0.73.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 CHANGED
@@ -6,7 +6,7 @@ require("dotenv").config({path: path.join(__dirname, "./.env")})
6
6
  const yargs = require("yargs/yargs")
7
7
  const {hideBin} = require("yargs/helpers")
8
8
 
9
- const start_server = require("./cli/start_server")
9
+ const start_server_infrastructure = require("./cli/start_server_infrastructure")
10
10
  const build_server = require("./cli/build_server")
11
11
  const run_agent = require("./cli/run_agent")
12
12
 
@@ -14,9 +14,9 @@ let is_command = false
14
14
 
15
15
 
16
16
  const args = yargs(hideBin(process.argv))
17
- .command("start", "run server/infrastructure", () => {}, (args) => {
17
+ .command("start", "runs server/infrastructure", () => {}, (args) => {
18
18
  is_command = true
19
- start_server(args)
19
+ start_server_infrastructure(args)
20
20
  })
21
21
  .command("agent", "run the agent", () => {}, (args) => {
22
22
  is_command = true
package/cli/run_native.js CHANGED
@@ -3,13 +3,17 @@ const {spawn} = require("child_process")
3
3
  const path = require("path")
4
4
  const fs = require("fs")
5
5
 
6
+ const colors = require("picocolors")
7
+ const validator = require("validator")
6
8
  const dotenv = require("dotenv")
7
9
  const mkdirp = require("mkdirp")
8
10
 
9
- // TODO: verify mongod and redis-sever executables are present
11
+ // TODO: verify mongod and redis-sever and elasticsearch executables are present
10
12
  // and have the right version
11
13
 
12
- // "redis-server", "/usr/local/etc/redis/redis.conf", "--port", $WORKER_QUEUE_PORT
14
+ const NO_PRINT_LIST = [
15
+ // "database",
16
+ ]
13
17
 
14
18
  // load env
15
19
  const get_env = () => {
@@ -19,54 +23,102 @@ const get_env = () => {
19
23
  return env
20
24
  }
21
25
 
22
- const init_processes = () => {
26
+ const init_processes = (args) => {
23
27
  const env = get_env()
24
28
 
25
29
  const infrastructure_conf_dir = path.join(__dirname, "../infrastructure")
26
30
 
27
- // create data dirs
31
+ // db storage
28
32
  const db_path = path.join(process.cwd(), "../infrastructure/data/database/db/")
29
- const db_logs_path = path.join(process.cwd(), "../infrastructure/data/database/log/")
30
33
 
34
+ // db log file
35
+ const db_logs_path = path.join(process.cwd(), "../infrastructure/data/database/log/logs.txt")
36
+
37
+ // session-store + worker-queue
31
38
  const session_store_dir = path.join(process.cwd(), "../infrastructure/data/session-store/data")
39
+ const session_store_logs_path = path.join(process.cwd(), "../infrastructure/data/session-store/log/logs.txt")
40
+ const worker_queue_dir = path.join(process.cwd(), "../infrastructure/data/worker-queue/data")
41
+ const worker_queue_logs_path = path.join(process.cwd(), "../infrastructure/data/worker-queue/log/logs.txt")
32
42
 
33
43
  // TODO: add a redis cache
34
44
  const processes = [
35
45
  // web server
36
46
  // TODO: do not use yarn dev server command
47
+ // use command: rb-server dev
37
48
  {
38
49
  name: "server",
39
50
  dirs: [],
51
+ // yarn dev
40
52
  cmd: ["yarn", ["dev"]]
41
53
  },
42
54
  // mongodb database
43
55
  {
44
56
  name: "database",
45
57
  dirs: [
46
- db_path, db_logs_path
58
+ db_path,
59
+ path.dirname(db_logs_path),
47
60
  ],
48
61
  cmd: ["mongod", [
49
62
  "--quiet",
50
63
  "--dbpath", db_path,
51
64
  "--port", env.DATABASE_PORT,
52
65
  // "--bind_ip_all",
53
- // "--logpath", "/var/log/logs.txt",
66
+ // if in verbose mode, print to stdout, else write to file
67
+ ...(args.verbose ? [] : ["--logpath", db_logs_path]),
54
68
  "--replSet", "rs0"
55
69
  ]]
56
70
  },
71
+ // session-store
57
72
  {
58
73
  name: "session-store",
59
74
  dirs: [
60
75
  session_store_dir,
76
+ path.dirname(session_store_logs_path),
61
77
  ],
62
78
  cmd: ["redis-server", [
63
79
  path.join(infrastructure_conf_dir, "./redis/redis.conf"),
64
80
  "--dir", session_store_dir,
65
81
  "--port", env.SESSION_STORE_PORT,
82
+ ...(args.verbose ? [] : ["--logfile", session_store_logs_path]),
83
+ ]]
84
+ },
85
+ // worker-queue
86
+ {
87
+ name: "worker-queue",
88
+ dirs: [
89
+ worker_queue_dir,
90
+ path.dirname(worker_queue_logs_path),
91
+ ],
92
+ cmd: ["redis-server", [
93
+ path.join(infrastructure_conf_dir, "./redis/redis.conf"),
94
+ "--dir", worker_queue_dir,
95
+ "--port", env.WORKER_QUEUE_PORT,
96
+ ...(args.verbose ? [] : ["--logfile", worker_queue_logs_path]),
66
97
  ]]
67
98
  },
68
99
  ]
69
100
 
101
+ // add search-index elasticsearch if port is defined
102
+ if (env.SEARCH_INDEX_PORT && validator.isPort(env.SEARCH_INDEX_PORT)) {
103
+ const data_dir = path.join(process.cwd(), "../infrastructure/data/search-index/data")
104
+ const logs_dir = path.join(process.cwd(), "../infrastructure/data/search-index/logs")
105
+ processes.push({
106
+ name: "search-index",
107
+ dirs: [
108
+ data_dir,
109
+ logs_dir,
110
+ ],
111
+ cmd: ["elasticsearch", [
112
+ "-s",
113
+ "-E", `path.logs=${logs_dir}`,
114
+ "-E", `http.port=${env.SEARCH_INDEX_PORT}`,
115
+ "-E", `path.data=${data_dir}`,
116
+ "-E", "discovery.type=single-node",
117
+ "-E", "ingest.geoip.downloader.enabled=false",
118
+ ]]
119
+ })
120
+ }
121
+
70
122
  // create missing directories
71
123
  processes.forEach((item) => {
72
124
  item.dirs.forEach((dir) => {
@@ -81,22 +133,32 @@ const init_processes = () => {
81
133
 
82
134
  // TODO: run each native process from list
83
135
  // TODO: handle process close
84
- const run_native = (infrastructure_dir, proj_prefix) => {
85
- console.log("running in NATIVE mode")
136
+ const run_native = (infrastructure_dir, proj_prefix, args) => {
137
+ console.log(`running in ${colors.bold(colors.magenta("NATIVE"))} mode`)
86
138
 
87
- const processes = init_processes()
139
+ const processes = init_processes(args)
88
140
 
89
141
  const run_process = (item) => {
90
- // console.log("start process", item)
142
+ // console.log("run_native:run_process:item", item)
91
143
  const ps = spawn(item.cmd[0], item.cmd[1], {env: {...process.env, CONTAINER_MODE: "native"}})
92
144
 
93
- ps.stdout.on("data", (data) => {
94
- process.stdout.write(`${item.name}: ${data.toString()}`)
95
- })
145
+ // TODO: add flag to force print
146
+ if (!NO_PRINT_LIST.includes(item.name)) {
96
147
 
97
- ps.stderr.on("data", (data) => {
98
- process.stderr.write(`${item.name}: ${data.toString()}`)
99
- })
148
+ let prefix = ""
149
+ // avoid printing [server] server:
150
+ if (!args.verbose && item.name !== "server") {
151
+ prefix = `${colors.green(item.name)}: `
152
+ }
153
+
154
+ ps.stdout.on("data", (data) => {
155
+ process.stdout.write(`${prefix}${data.toString()}`)
156
+ })
157
+
158
+ ps.stderr.on("data", (data) => {
159
+ process.stderr.write(`${prefix}${data.toString()}`)
160
+ })
161
+ }
100
162
  }
101
163
 
102
164
  const spawned = processes.map(run_process)
@@ -19,9 +19,9 @@ const start_server = async(args) => {
19
19
  const proj_prefix = path.basename(proj_parent_dir)
20
20
 
21
21
  if (runtime === "docker") {
22
- run_docker(infrastructure_dir, proj_prefix)
22
+ run_docker(infrastructure_dir, proj_prefix, args)
23
23
  } else if (runtime === "native") {
24
- run_native(infrastructure_dir, proj_prefix)
24
+ run_native(infrastructure_dir, proj_prefix, args)
25
25
  } else {
26
26
  throw new Error("unknown runtime")
27
27
  }
package/database.js CHANGED
@@ -24,6 +24,7 @@ module.exports = async() => {
24
24
  })
25
25
 
26
26
  mongoose.connection.on("disconnected", (arg) => {
27
+ // TODO: add tracing
27
28
  console.log("Mongoose disconnected", arg)
28
29
  })
29
30
 
package/index.js CHANGED
@@ -4,8 +4,6 @@ const database = require("./database")
4
4
  const express = require("./express")
5
5
  const rpc_router = require("./rpc/rpc_router")
6
6
 
7
-
8
-
9
7
  module.exports = {
10
8
  client_router,
11
9
  database,
@@ -0,0 +1,88 @@
1
+ # ======================== Elasticsearch Configuration =========================
2
+ #
3
+ # NOTE: Elasticsearch comes with reasonable defaults for most settings.
4
+ # Before you set out to tweak and tune the configuration, make sure you
5
+ # understand what are you trying to accomplish and the consequences.
6
+ #
7
+ # The primary way of configuring a node is via this file. This template lists
8
+ # the most important settings you may want to configure for a production cluster.
9
+ #
10
+ # Please consult the documentation for further information on configuration options:
11
+ # https://www.elastic.co/guide/en/elasticsearch/reference/index.html
12
+ #
13
+ # ---------------------------------- Cluster -----------------------------------
14
+ #
15
+ # Use a descriptive name for your cluster:
16
+ #
17
+ #cluster.name: my-application
18
+ #
19
+ # ------------------------------------ Node ------------------------------------
20
+ #
21
+ # Use a descriptive name for the node:
22
+ #
23
+ #node.name: node-1
24
+ #
25
+ # Add custom attributes to the node:
26
+ #
27
+ #node.attr.rack: r1
28
+ #
29
+ # ----------------------------------- Paths ------------------------------------
30
+ #
31
+ # Path to directory where to store the data (separate multiple locations by comma):
32
+ #
33
+ @path.data@
34
+ #
35
+ # Path to log files:
36
+ #
37
+ @path.logs@
38
+ #
39
+ # ----------------------------------- Memory -----------------------------------
40
+ #
41
+ # Lock the memory on startup:
42
+ #
43
+ #bootstrap.memory_lock: true
44
+ #
45
+ # Make sure that the heap size is set to about half the memory available
46
+ # on the system and that the owner of the process is allowed to use this
47
+ # limit.
48
+ #
49
+ # Elasticsearch performs poorly when the system is swapping the memory.
50
+ #
51
+ # ---------------------------------- Network -----------------------------------
52
+ #
53
+ # By default Elasticsearch is only accessible on localhost. Set a different
54
+ # address here to expose this node on the network:
55
+ #
56
+ #network.host: 192.168.0.1
57
+ #
58
+ # By default Elasticsearch listens for HTTP traffic on the first free port it
59
+ # finds starting at 9200. Set a specific HTTP port here:
60
+ #
61
+ #http.port: 9200
62
+ #
63
+ # For more information, consult the network module documentation.
64
+ #
65
+ # --------------------------------- Discovery ----------------------------------
66
+ #
67
+ # Pass an initial list of hosts to perform discovery when this node is started:
68
+ # The default list of hosts is ["127.0.0.1", "[::1]"]
69
+ #
70
+ #discovery.seed_hosts: ["host1", "host2"]
71
+ #
72
+ # Bootstrap the cluster using an initial set of master-eligible nodes:
73
+ #
74
+ #cluster.initial_master_nodes: ["node-1", "node-2"]
75
+ #
76
+ # For more information, consult the discovery and cluster formation module documentation.
77
+ #
78
+ # --------------------------------- Readiness ----------------------------------
79
+ #
80
+ # Enable an unauthenticated TCP readiness endpoint on localhost
81
+ #
82
+ #readiness.port: 9399
83
+ #
84
+ # ---------------------------------- Various -----------------------------------
85
+ #
86
+ # Allow wildcard deletion of indices:
87
+ #
88
+ #action.destructive_requires_name: false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.70.0",
3
+ "version": "0.73.0",
4
4
  "license": "SSPL-1.0",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -10,7 +10,7 @@
10
10
  "test": "echo \"Error: no test specified\" && exit 0"
11
11
  },
12
12
  "dependencies": {
13
- "@rpcbase/agent": "0.7.0",
13
+ "@rpcbase/agent": "0.9.0",
14
14
  "body-parser": "1.20.0",
15
15
  "connect-redis": "6.1.3",
16
16
  "cors": "2.8.5",
@@ -19,7 +19,8 @@
19
19
  "express": "4.18.1",
20
20
  "express-session": "1.17.3",
21
21
  "glob": "8.0.3",
22
- "mongoose": "6.3.5",
22
+ "mongoose": "6.4.0",
23
+ "picocolors": "1.0.0",
23
24
  "postmark": "3.0.11",
24
25
  "redis": "4.1.0",
25
26
  "validator": "13.7.0",