From 1be0435c5fb24eaa0b276e19038224b110a71a7d Mon Sep 17 00:00:00 2001 From: Varun Sharma Date: Tue, 30 Nov 2021 15:12:30 -0800 Subject: [PATCH] Print service logs on failure --- dist/post/index.js | 6 ++++++ dist/post/index.js.map | 2 +- src/cleanup.ts | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/dist/post/index.js b/dist/post/index.js index 4407cc3..742c72a 100644 --- a/dist/post/index.js +++ b/dist/post/index.js @@ -26,6 +26,8 @@ __nccwpck_require__.r(__webpack_exports__); ;// CONCATENATED MODULE: external "fs" const external_fs_namespaceObject = require("fs"); +;// CONCATENATED MODULE: external "child_process" +const external_child_process_namespaceObject = require("child_process"); ;// CONCATENATED MODULE: ./src/cleanup.ts var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } @@ -37,6 +39,7 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume }); }; + (() => __awaiter(void 0, void 0, void 0, function* () { if (process.platform !== "linux") { console.log("Only runs on linux"); @@ -68,6 +71,9 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume var content = external_fs_namespaceObject.readFileSync(status, "utf-8"); console.log(content); } + else { + external_child_process_namespaceObject.execSync("sudo journalctl -u agent.service"); + } }))(); function sleep(ms) { return new Promise((resolve) => { diff --git a/dist/post/index.js.map b/dist/post/index.js.map index 8ee5fef..e172c14 100644 --- a/dist/post/index.js.map +++ b/dist/post/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sources":["../webpack://step-security-harden-runner/webpack/bootstrap","../webpack://step-security-harden-runner/webpack/runtime/make namespace object","../webpack://step-security-harden-runner/webpack/runtime/compat","../webpack://step-security-harden-runner/external \"fs\"","../webpack://step-security-harden-runner/./src/cleanup.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","\nif (typeof __webpack_require__ !== 'undefined') __webpack_require__.ab = __dirname + \"/\";","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"fs\");","import * as fs from \"fs\";\n\n(async () => {\n if (process.platform !== \"linux\") {\n console.log(\"Only runs on linux\");\n return;\n }\n\n fs.writeFileSync(\n \"/home/agent/post_event.json\",\n JSON.stringify({ event: \"post\" })\n );\n\n var doneFile = \"/home/agent/done.json\";\n var counter = 0;\n while (true) {\n if (!fs.existsSync(doneFile)) {\n counter++;\n if (counter > 10) {\n console.log(\"timed out\");\n\n break;\n }\n await sleep(1000);\n } // The file *does* exist\n else {\n break;\n }\n }\n\n var log = \"/home/agent/agent.log\";\n console.log(\"log:\");\n var content = fs.readFileSync(log, \"utf-8\");\n console.log(content);\n var status = \"/home/agent/agent.status\";\n if (fs.existsSync(status)) {\n console.log(\"status:\");\n var content = fs.readFileSync(status, \"utf-8\");\n console.log(content);\n }\n})();\n\nfunction sleep(ms) {\n return new Promise((resolve) => {\n setTimeout(resolve, ms);\n });\n}\n"],"mappings":";;AAAA;AACA;AACA;;;;ACFA;AACA;AACA;AACA;AACA;AACA;AACA;;;;ACNA;AACA;;;;;;;;ACDA;;;;;;;;;;;ACAA;AAEA;AACA;AACA;AACA;AACA;AAEA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;;;;A","sourceRoot":""} \ No newline at end of file +{"version":3,"file":"index.js","sources":["../webpack://step-security-harden-runner/webpack/bootstrap","../webpack://step-security-harden-runner/webpack/runtime/make namespace object","../webpack://step-security-harden-runner/webpack/runtime/compat","../webpack://step-security-harden-runner/external \"fs\"","../webpack://step-security-harden-runner/external \"child_process\"","../webpack://step-security-harden-runner/./src/cleanup.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","\nif (typeof __webpack_require__ !== 'undefined') __webpack_require__.ab = __dirname + \"/\";","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"fs\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"child_process\");","import * as fs from \"fs\";\nimport * as cp from \"child_process\";\n\n(async () => {\n if (process.platform !== \"linux\") {\n console.log(\"Only runs on linux\");\n return;\n }\n\n fs.writeFileSync(\n \"/home/agent/post_event.json\",\n JSON.stringify({ event: \"post\" })\n );\n\n var doneFile = \"/home/agent/done.json\";\n var counter = 0;\n while (true) {\n if (!fs.existsSync(doneFile)) {\n counter++;\n if (counter > 10) {\n console.log(\"timed out\");\n\n break;\n }\n await sleep(1000);\n } // The file *does* exist\n else {\n break;\n }\n }\n\n var log = \"/home/agent/agent.log\";\n console.log(\"log:\");\n var content = fs.readFileSync(log, \"utf-8\");\n console.log(content);\n var status = \"/home/agent/agent.status\";\n if (fs.existsSync(status)) {\n console.log(\"status:\");\n var content = fs.readFileSync(status, \"utf-8\");\n console.log(content);\n } else {\n cp.execSync(\"sudo journalctl -u agent.service\");\n }\n})();\n\nfunction sleep(ms) {\n return new Promise((resolve) => {\n setTimeout(resolve, ms);\n });\n}\n"],"mappings":";;AAAA;AACA;AACA;;;;ACFA;AACA;AACA;AACA;AACA;AACA;AACA;;;;ACNA;AACA;;;;;;;;ACDA;;ACAA;;;;;;;;;;;ACAA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;;;;A","sourceRoot":""} \ No newline at end of file diff --git a/src/cleanup.ts b/src/cleanup.ts index 023481e..03bfce5 100644 --- a/src/cleanup.ts +++ b/src/cleanup.ts @@ -1,4 +1,5 @@ import * as fs from "fs"; +import * as cp from "child_process"; (async () => { if (process.platform !== "linux") { @@ -37,6 +38,8 @@ import * as fs from "fs"; console.log("status:"); var content = fs.readFileSync(status, "utf-8"); console.log(content); + } else { + cp.execSync("sudo journalctl -u agent.service"); } })();