drew %!s(int64=6) %!d(string=hai) anos
pai
achega
d76c9b5dbb
Modificáronse 3 ficheiros con 129 adicións e 15 borrados
  1. 95 0
      package-lock.json
  2. 4 1
      package.json
  3. 30 14
      server.js

+ 95 - 0
package-lock.json

@@ -96,6 +96,19 @@
         "assert-plus": "^1.0.0"
       }
     },
+    "date-format": {
+      "version": "3.0.0",
+      "resolved": "https://registry.npm.taobao.org/date-format/download/date-format-3.0.0.tgz",
+      "integrity": "sha1-64eANlx9KxURB4+0keZHl4DzrZU="
+    },
+    "debug": {
+      "version": "4.1.1",
+      "resolved": "https://registry.npm.taobao.org/debug/download/debug-4.1.1.tgz",
+      "integrity": "sha1-O3ImAlUQnGtYnO4FDx1RYTlmR5E=",
+      "requires": {
+        "ms": "^2.1.1"
+      }
+    },
     "delayed-stream": {
       "version": "1.0.0",
       "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
@@ -130,6 +143,11 @@
       "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz",
       "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw=="
     },
+    "flatted": {
+      "version": "2.0.1",
+      "resolved": "https://registry.npm.taobao.org/flatted/download/flatted-2.0.1.tgz",
+      "integrity": "sha1-aeV8qo8OrLwoHS4stFjUb9tEngg="
+    },
     "forever-agent": {
       "version": "0.6.1",
       "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz",
@@ -145,6 +163,16 @@
         "mime-types": "^2.1.12"
       }
     },
+    "fs-extra": {
+      "version": "8.1.0",
+      "resolved": "https://registry.npm.taobao.org/fs-extra/download/fs-extra-8.1.0.tgz",
+      "integrity": "sha1-SdQ8RaiM2Wd2aMt74bRu/bjS4cA=",
+      "requires": {
+        "graceful-fs": "^4.2.0",
+        "jsonfile": "^4.0.0",
+        "universalify": "^0.1.0"
+      }
+    },
     "getpass": {
       "version": "0.1.7",
       "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz",
@@ -153,6 +181,11 @@
         "assert-plus": "^1.0.0"
       }
     },
+    "graceful-fs": {
+      "version": "4.2.3",
+      "resolved": "https://registry.npm.taobao.org/graceful-fs/download/graceful-fs-4.2.3.tgz",
+      "integrity": "sha1-ShL/G2A3bvCYYsIJPt2Qgyi+hCM="
+    },
     "har-schema": {
       "version": "2.0.0",
       "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz",
@@ -182,6 +215,11 @@
       "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz",
       "integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg=="
     },
+    "is-port-reachable": {
+      "version": "3.0.0",
+      "resolved": "https://registry.npm.taobao.org/is-port-reachable/download/is-port-reachable-3.0.0.tgz",
+      "integrity": "sha1-7fch59NU5uAMvrD8F0rYm99gVrM="
+    },
     "is-typedarray": {
       "version": "1.0.0",
       "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",
@@ -212,6 +250,14 @@
       "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz",
       "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus="
     },
+    "jsonfile": {
+      "version": "4.0.0",
+      "resolved": "https://registry.npm.taobao.org/jsonfile/download/jsonfile-4.0.0.tgz",
+      "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=",
+      "requires": {
+        "graceful-fs": "^4.1.6"
+      }
+    },
     "jsprim": {
       "version": "1.4.1",
       "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz",
@@ -228,6 +274,18 @@
       "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
       "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A=="
     },
+    "log4js": {
+      "version": "6.1.2",
+      "resolved": "https://registry.npm.taobao.org/log4js/download/log4js-6.1.2.tgz?cache=0&sync_timestamp=1581380060991&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Flog4js%2Fdownload%2Flog4js-6.1.2.tgz",
+      "integrity": "sha1-BGiOH0uAgMEnt9zLDbHHWcuyXcQ=",
+      "requires": {
+        "date-format": "^3.0.0",
+        "debug": "^4.1.1",
+        "flatted": "^2.0.1",
+        "rfdc": "^1.1.4",
+        "streamroller": "^2.2.3"
+      }
+    },
     "mime-db": {
       "version": "1.43.0",
       "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.43.0.tgz",
@@ -241,6 +299,11 @@
         "mime-db": "1.43.0"
       }
     },
+    "ms": {
+      "version": "2.1.2",
+      "resolved": "https://registry.npm.taobao.org/ms/download/ms-2.1.2.tgz",
+      "integrity": "sha1-0J0fNXtEP0kzgqjrPM0YOHKuYAk="
+    },
     "node-ssh": {
       "version": "7.0.0",
       "resolved": "https://registry.npmjs.org/node-ssh/-/node-ssh-7.0.0.tgz",
@@ -332,6 +395,11 @@
         "lodash": "^4.17.15"
       }
     },
+    "rfdc": {
+      "version": "1.1.4",
+      "resolved": "https://registry.npm.taobao.org/rfdc/download/rfdc-1.1.4.tgz",
+      "integrity": "sha1-unLME2egzNnPgahws7WL060H+MI="
+    },
     "safe-buffer": {
       "version": "5.2.0",
       "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz",
@@ -407,6 +475,23 @@
       "resolved": "https://registry.npmjs.org/stealthy-require/-/stealthy-require-1.1.1.tgz",
       "integrity": "sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks="
     },
+    "streamroller": {
+      "version": "2.2.3",
+      "resolved": "https://registry.npm.taobao.org/streamroller/download/streamroller-2.2.3.tgz",
+      "integrity": "sha1-uVyfrUTi6JAF0kIUFIaztJYsLSg=",
+      "requires": {
+        "date-format": "^2.1.0",
+        "debug": "^4.1.1",
+        "fs-extra": "^8.1.0"
+      },
+      "dependencies": {
+        "date-format": {
+          "version": "2.1.0",
+          "resolved": "https://registry.npm.taobao.org/date-format/download/date-format-2.1.0.tgz",
+          "integrity": "sha1-MdW16iEc9f12TNOLr50DPffhJc8="
+        }
+      }
+    },
     "streamsearch": {
       "version": "0.1.2",
       "resolved": "https://registry.npm.taobao.org/streamsearch/download/streamsearch-0.1.2.tgz",
@@ -434,6 +519,11 @@
       "resolved": "http://registry.npm.taobao.org/tweetnacl/download/tweetnacl-0.14.5.tgz",
       "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q="
     },
+    "universalify": {
+      "version": "0.1.2",
+      "resolved": "https://registry.npm.taobao.org/universalify/download/universalify-0.1.2.tgz",
+      "integrity": "sha1-tkb2m+OULavOzJ1mOcgNwQXvqmY="
+    },
     "uri-js": {
       "version": "4.2.2",
       "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz",
@@ -456,6 +546,11 @@
         "core-util-is": "1.0.2",
         "extsprintf": "^1.2.0"
       }
+    },
+    "ws": {
+      "version": "7.2.1",
+      "resolved": "https://registry.npm.taobao.org/ws/download/ws-7.2.1.tgz?cache=0&sync_timestamp=1576314828024&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fws%2Fdownload%2Fws-7.2.1.tgz",
+      "integrity": "sha1-A+1SQjzXRAhLLPQu0ZfItlqTa44="
     }
   }
 }

+ 4 - 1
package.json

@@ -4,9 +4,12 @@
   "description": "修改配置文件config.js 下载安装nodejs http://nodejs.cn/download/ 打开widnow+R 输入cmd 依次输入以下命令 cd /K 项目文件夹 npm config set registry https://registry.npm.taobao.org npm install node manage.js",
   "main": "index.js",
   "dependencies": {
+    "is-port-reachable": "^3.0.0",
+    "log4js": "^6.1.2",
     "node-ssh": "^7.0.0",
     "request": "^2.88.2",
-    "request-promise": "^4.2.5"
+    "request-promise": "^4.2.5",
+    "ws": "^7.2.1"
   },
   "devDependencies": {},
   "scripts": {

+ 30 - 14
server.js

@@ -13,7 +13,7 @@ ssh = new node_ssh();
 ssh.connect({
     host: host,
     username: "root",
-    port: 22,
+    port: 8001,
     password: config.password
 })
     .then(async function() {
@@ -76,19 +76,35 @@ ssh.connect({
             await ssh.execCommand("sudo apt-get install -y nodejs", option);
             console.log("node安装完成");
         }
-        await ssh.execCommand("npm install", {
-            ...option,
-            cwd: "/root/autoTrade"
-        });
-        await ssh.execCommand("ls -la", { ...option, cwd: "/root/autoTrade" });
-        await ssh.execCommand("killall node", {
-            ...option,
-            cwd: "/root/autoTrade"
-        });
-        await ssh.execCommand(`node index.js ${index}`, {
-            ...option,
-            cwd: "/root/autoTrade"
-        });
+        await ssh
+            .execCommand("npm install", {
+                ...option,
+                cwd: "/root/autoTrade"
+            })
+            .catch(e => {
+                console.log("npm install failed");
+            });
+        await ssh
+            .execCommand("ls -la", { ...option, cwd: "/root/autoTrade" })
+            .catch(e => {
+                console.log("ls -la failed");
+            });
+        await ssh
+            .execCommand("killall node", {
+                ...option,
+                cwd: "/root/autoTrade"
+            })
+            .catch(e => {
+                console.log("killall node failed");
+            });
+        await ssh
+            .execCommand(`node index.js ${index}`, {
+                ...option,
+                cwd: "/root/autoTrade"
+            })
+            .catch(e => {
+                console.log("node index.js failed");
+            });
     })
     .catch(e => {
         console.log(e);