hola-server 0.8.8 → 0.8.10

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 +28 -8
  2. package/package.json +1 -1
package/core/bash.js CHANGED
@@ -19,6 +19,30 @@ const get_log_file = async () => {
19
19
  * @returns
20
20
  */
21
21
  const run_script = async (host, script, log_extra) => {
22
+ return new Promise((resolve) => {
23
+ 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) => {
24
+ if (error) {
25
+ if (is_log_error()) {
26
+ log_error(LOG_BASH, "error running on host:" + host.name + " the script:" + script + ",error:" + error, log_extra);
27
+ }
28
+ resolve({ stdout: stdout, err: "error running the script:" + script + ",error:" + error });
29
+ } else {
30
+ if (is_log_debug()) {
31
+ log_debug(LOG_BASH, "executing on host:" + host.name + ", script:" + script + ",stdout:" + stdout, log_extra);
32
+ }
33
+ resolve({ stdout: stdout });
34
+ }
35
+ });
36
+ });
37
+ };
38
+
39
+ /**
40
+ * Run script and get stdout and this use file redirect to avoid progress bar issue
41
+ * @param {host info,contains user,ip and password} host
42
+ * @param {commands to run} script
43
+ * @returns
44
+ */
45
+ const run_script_extra = async (host, script, log_extra) => {
22
46
  const log_file = await get_log_file();
23
47
 
24
48
  return new Promise((resolve) => {
@@ -41,22 +65,18 @@ const run_script = async (host, script, log_extra) => {
41
65
  };
42
66
 
43
67
  const run_script_file = async (host, script_file, log_extra) => {
44
- const log_file = await get_log_file();
45
-
46
68
  return new Promise((resolve) => {
47
- exec(`ssh ${host.auth} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p ${host.port} ${host.user}@${host.ip} /bin/bash < ${script_file} > ${log_file}`, (error, stdout) => {
69
+ exec(`ssh ${host.auth} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p ${host.port} ${host.user}@${host.ip} /bin/bash < ${script_file}`, (error, stdout) => {
48
70
  if (error) {
49
71
  if (is_log_error()) {
50
72
  log_error(LOG_BASH, "error running on host:" + host.name + " the script_file:" + script_file + ",error:" + error, log_extra);
51
73
  }
52
74
  resolve({ stdout: stdout, err: "error running the script:" + script_file + ",error:" + error });
53
75
  } else {
54
- const output = fs.readFileSync(log_file, { encoding: 'utf8', flag: 'r' });
55
76
  if (is_log_debug()) {
56
- log_debug(LOG_BASH, "executing on host:" + host.name + ", script_file:" + script_file + ",stdout:" + output, log_extra);
77
+ log_debug(LOG_BASH, "executing on host:" + host.name + ", script_file:" + script_file + ",stdout:" + stdout, log_extra);
57
78
  }
58
- resolve({ stdout: output });
59
- fs.unlinkSync(log_file);
79
+ resolve({ stdout: stdout });
60
80
  }
61
81
  });
62
82
  });
@@ -322,4 +342,4 @@ const stop_process = async (host, process_name, stop_cmd, using_full, log_extra)
322
342
  return has_process;
323
343
  }
324
344
 
325
- module.exports = { stop_process, scp, scpr, run_script, run_script_file, run_simple_cmd, run_local_cmd, run_simple_local_cmd, get_info, get_system_attributes, read_key_value_line, read_obj_line };
345
+ module.exports = { stop_process, scp, scpr, run_script, run_script_extra, run_script_file, run_simple_cmd, run_local_cmd, run_simple_local_cmd, get_info, get_system_attributes, read_key_value_line, read_obj_line };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hola-server",
3
- "version": "0.8.8",
3
+ "version": "0.8.10",
4
4
  "description": "a meta programming framework used to build nodejs restful api",
5
5
  "main": "index.js",
6
6
  "scripts": {