hola-server 0.8.7 → 0.8.9

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 +26 -2
  2. package/package.json +1 -1
package/core/bash.js CHANGED
@@ -6,7 +6,7 @@ const { is_log_debug, is_log_error, log_debug, log_error } = require('../db/db')
6
6
  const LOG_BASH = "bash";
7
7
 
8
8
  const get_log_file = async () => {
9
- const home = await run_local_cmd("echo ~");
9
+ const home = await run_simple_local_cmd("echo ~");
10
10
  const log_dir = `${home}/.hola/ssh`;
11
11
  await run_local_cmd(`mkdir -p ${log_dir}`);
12
12
  return `${log_dir}/l_${random_code()}.log`;
@@ -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) => {
@@ -322,4 +346,4 @@ const stop_process = async (host, process_name, stop_cmd, using_full, log_extra)
322
346
  return has_process;
323
347
  }
324
348
 
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 };
349
+ 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.7",
3
+ "version": "0.8.9",
4
4
  "description": "a meta programming framework used to build nodejs restful api",
5
5
  "main": "index.js",
6
6
  "scripts": {