hola-server 0.8.4 → 0.8.5

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.
Files changed (2) hide show
  1. package/core/bash.js +29 -29
  2. package/package.json +1 -1
package/core/bash.js CHANGED
@@ -9,17 +9,17 @@ const LOG_BASH = "bash";
9
9
  * @param {commands to run} script
10
10
  * @returns
11
11
  */
12
- const run_script = async (host, script) => {
12
+ const run_script = async (host, script, log_extra) => {
13
13
  return new Promise((resolve) => {
14
14
  exec(`ssh ${host.auth} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p ${host.port} ${host.user}@${host.ip} /bin/bash <<'EOT' \n ${script} \nEOT\n`, { maxBuffer: 1024 * 150000 }, (error, stdout) => {
15
15
  if (error) {
16
16
  if (is_log_error()) {
17
- log_error(LOG_BASH, "error running on host:" + host.name + " the script:" + script + ",error:" + error);
17
+ log_error(LOG_BASH, "error running on host:" + host.name + " the script:" + script + ",error:" + error, log_extra);
18
18
  }
19
- resolve({ err: "error running the script:" + script + ",error:" + error });
19
+ resolve({ stdout: stdout, err: "error running the script:" + script + ",error:" + error });
20
20
  } else {
21
21
  if (is_log_debug()) {
22
- log_debug(LOG_BASH, "executing on host:" + host.name + ", script:" + script + ",stdout:" + stdout);
22
+ log_debug(LOG_BASH, "executing on host:" + host.name + ", script:" + script + ",stdout:" + stdout, log_extra);
23
23
  }
24
24
  resolve({ stdout: stdout });
25
25
  }
@@ -27,17 +27,17 @@ const run_script = async (host, script) => {
27
27
  });
28
28
  };
29
29
 
30
- const run_script_file = async (host, script_file) => {
30
+ const run_script_file = async (host, script_file, log_extra) => {
31
31
  return new Promise((resolve) => {
32
32
  exec(`ssh ${host.auth} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p ${host.port} ${host.user}@${host.ip} /bin/bash < ${script_file}`, (error, stdout) => {
33
33
  if (error) {
34
34
  if (is_log_error()) {
35
- log_error(LOG_BASH, "error running on host:" + host.name + " the script_file:" + script_file + ",error:" + error);
35
+ log_error(LOG_BASH, "error running on host:" + host.name + " the script_file:" + script_file + ",error:" + error, log_extra);
36
36
  }
37
- resolve({ err: "error running the script:" + script_file + ",error:" + error });
37
+ resolve({ stdout: stdout, err: "error running the script:" + script_file + ",error:" + error });
38
38
  } else {
39
39
  if (is_log_debug()) {
40
- log_debug(LOG_BASH, "executing on host:" + host.name + ", script_file:" + script_file + ",stdout:" + stdout);
40
+ log_debug(LOG_BASH, "executing on host:" + host.name + ", script_file:" + script_file + ",stdout:" + stdout, log_extra);
41
41
  }
42
42
  resolve({ stdout: stdout });
43
43
  }
@@ -57,7 +57,7 @@ const run_local_cmd = async (cmd, log_extra) => {
57
57
  if (is_log_error()) {
58
58
  log_error(LOG_BASH, "error running on local host with cmd:" + cmd + ",error:" + error, log_extra);
59
59
  }
60
- resolve({ err: "error running the cmd:" + cmd + ",error:" + error }, log_extra);
60
+ resolve({ stdout: stdout, err: "error running the cmd:" + cmd + ",error:" + error }, log_extra);
61
61
  } else {
62
62
  if (is_log_debug()) {
63
63
  log_debug(LOG_BASH, "executing on local host with cmd:" + cmd + ",stdout:" + stdout, log_extra);
@@ -75,17 +75,17 @@ const run_local_cmd = async (cmd, log_extra) => {
75
75
  * @param {local file path} locale_file
76
76
  * @returns
77
77
  */
78
- const scp = async (host, remote_file, local_file, extra) => {
78
+ const scp = async (host, remote_file, local_file, log_extra) => {
79
79
  return new Promise((resolve) => {
80
80
  exec(`sshpass -p '${host.pwd}' scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -P ${host.port} -q ${host.user}@${host.ip}:${remote_file} ${local_file}`, (error, stdout) => {
81
81
  if (error) {
82
82
  if (is_log_error()) {
83
- log_error(LOG_BASH, "error scp on host:" + host.name + " remote:" + remote_file + ",local:" + local_file + ",error:" + error, extra);
83
+ log_error(LOG_BASH, "error scp on host:" + host.name + " remote:" + remote_file + ",local:" + local_file + ",error:" + error, log_extra);
84
84
  }
85
- resolve({ err: "error scp:" + remote_file + " to locale:" + local_file + ",err:" + error });
85
+ resolve({ stdout: stdout, err: "error scp:" + remote_file + " to locale:" + local_file + ",err:" + error });
86
86
  } else {
87
87
  if (is_log_debug()) {
88
- log_debug(LOG_BASH, "executing scp on host:" + host.name + ", remote:" + remote_file + ",local:" + local_file + ",stdout:" + stdout, extra);
88
+ log_debug(LOG_BASH, "executing scp on host:" + host.name + ", remote:" + remote_file + ",local:" + local_file + ",stdout:" + stdout, log_extra);
89
89
  }
90
90
  resolve({ stdout: stdout });
91
91
  }
@@ -100,17 +100,17 @@ const scp = async (host, remote_file, local_file, extra) => {
100
100
  * @param {remote file path} remote_file
101
101
  * @returns
102
102
  */
103
- const scpr = async (host, local_file, remote_file, extra) => {
103
+ const scpr = async (host, local_file, remote_file, log_extra) => {
104
104
  return new Promise((resolve) => {
105
105
  exec(`sshpass -p '${host.pwd}' scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -P ${host.port} -q ${local_file} ${host.user}@${host.ip}:${remote_file}`, (error, stdout) => {
106
106
  if (error) {
107
107
  if (is_log_error()) {
108
- log_error(LOG_BASH, "error scpr on host:" + host.name + " remote:" + remote_file + ",local:" + local_file + ",error:" + error, extra);
108
+ log_error(LOG_BASH, "error scpr on host:" + host.name + " remote:" + remote_file + ",local:" + local_file + ",error:" + error, log_extra);
109
109
  }
110
- resolve({ err: "error scp:" + remote_file + " to locale:" + local_file + ",err:" + error });
110
+ resolve({ stdout: stdout, err: "error scp:" + remote_file + " to locale:" + local_file + ",err:" + error });
111
111
  } else {
112
112
  if (is_log_debug()) {
113
- log_debug(LOG_BASH, "executing scpr on host:" + host.name + ", remote:" + remote_file + ",local:" + local_file + ",stdout:" + stdout, extra);
113
+ log_debug(LOG_BASH, "executing scpr on host:" + host.name + ", remote:" + remote_file + ",local:" + local_file + ",stdout:" + stdout, log_extra);
114
114
  }
115
115
  resolve({ stdout: stdout });
116
116
  }
@@ -124,8 +124,8 @@ const scpr = async (host, local_file, remote_file, extra) => {
124
124
  * @param {command to run} cmd
125
125
  * @returns
126
126
  */
127
- const run_simple_cmd = async (host, cmd) => {
128
- const { err, stdout } = await run_script(host, cmd);
127
+ const run_simple_cmd = async (host, cmd, log_extra) => {
128
+ const { err, stdout } = await run_script(host, cmd, log_extra);
129
129
  if (err) {
130
130
  return null;
131
131
  } else {
@@ -138,8 +138,8 @@ const run_simple_cmd = async (host, cmd) => {
138
138
  * @param {command to run} cmd
139
139
  * @returns
140
140
  */
141
- const run_simple_local_cmd = async (cmd) => {
142
- const { err, stdout } = await run_local_cmd(cmd);
141
+ const run_simple_local_cmd = async (cmd, log_extra) => {
142
+ const { err, stdout } = await run_local_cmd(cmd, log_extra);
143
143
  if (err) {
144
144
  return null;
145
145
  } else {
@@ -164,11 +164,11 @@ const run_simple_local_cmd = async (cmd) => {
164
164
  * @param {key to retrieve info} key
165
165
  * @returns
166
166
  */
167
- const get_info = (stdout, key) => {
167
+ const get_info = (stdout, key, log_extra) => {
168
168
  const word_key = key.split(" ").join("\\s+");
169
169
  const regex = new RegExp(`\n\\s?${word_key}\\s?:(.*)\\s`, 'g');
170
170
  if (is_log_debug()) {
171
- log_debug(LOG_BASH, "get_info and regex:" + JSON.stringify(regex));
171
+ log_debug(LOG_BASH, "get_info and regex:" + JSON.stringify(regex), log_extra);
172
172
  }
173
173
 
174
174
  const results = stdout.matchAll(regex);
@@ -179,7 +179,7 @@ const get_info = (stdout, key) => {
179
179
  }
180
180
 
181
181
  if (is_log_debug()) {
182
- log_debug(LOG_BASH, "get_info and matched:" + JSON.stringify(matched));
182
+ log_debug(LOG_BASH, "get_info and matched:" + JSON.stringify(matched), log_extra);
183
183
  }
184
184
  return matched;
185
185
  }
@@ -285,22 +285,22 @@ const read_obj_line = (stdout, keys, ignore = 1, delimiter = " ") => {
285
285
  * @param {host info,contains user,ip and password} host
286
286
  * @param {*} attrs {name:"attr name",cmd:"command to get the attr"}
287
287
  */
288
- const get_system_attributes = async (host, attrs) => {
288
+ const get_system_attributes = async (host, attrs, log_extra) => {
289
289
  const obj = {};
290
290
  for (let i = 0; i < attrs.length; i++) {
291
291
  const attr = attrs[i];
292
- const value = await run_simple_cmd(host, attr.cmd);
292
+ const value = await run_simple_cmd(host, attr.cmd, log_extra);
293
293
  value && (obj[attr.name] = value);
294
294
  }
295
295
  return obj;
296
296
  }
297
297
 
298
- const stop_process = async (host, process_name, stop_cmd, using_full) => {
298
+ const stop_process = async (host, process_name, stop_cmd, using_full, log_extra) => {
299
299
  const grep_cmd = using_full == true ? `pgrep -f "${process_name}" | wc -l` : `pgrep ${process_name} | wc -l`;
300
- const { stdout } = await run_script(host, grep_cmd);
300
+ const { stdout } = await run_script(host, grep_cmd, log_extra);
301
301
  const has_process = stdout && parseInt(stdout) > 0;
302
302
  if (has_process) {
303
- await run_script(host, stop_cmd);
303
+ await run_script(host, stop_cmd, log_extra);
304
304
  }
305
305
  return has_process;
306
306
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hola-server",
3
- "version": "0.8.4",
3
+ "version": "0.8.5",
4
4
  "description": "a meta programming framework used to build nodejs restful api",
5
5
  "main": "index.js",
6
6
  "scripts": {