diff --git a/.github/workflows/cronjob.yml b/.github/workflows/cronjob.yml new file mode 100644 index 00000000..6d8bfa33 --- /dev/null +++ b/.github/workflows/cronjob.yml @@ -0,0 +1,16 @@ +name: Ping Server + +on: + schedule: + - cron: "*/10 * * * *" + +jobs: + ping: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Run Ping Script + run: /usr/bin/node /server/serverPing.js diff --git a/package-lock.json b/package-lock.json index e464800a..74a61b45 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "@babel/runtime": "^7.22.6", "bootstrap": "^5.3.2", + "child_process": "^1.0.2", "dotenv": "^16.3.1", "express": "^4.18.2", "helmet": "^7.0.0", @@ -20,6 +21,7 @@ "react-player": "^2.13.0", "react-range": "^1.8.14", "react-slider": "^2.0.6", + "util": "^0.12.5", "winston": "^3.10.0" }, "devDependencies": { @@ -3159,7 +3161,6 @@ }, "node_modules/available-typed-arrays": { "version": "1.0.5", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -3656,6 +3657,11 @@ "node": ">=4" } }, + "node_modules/child_process": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/child_process/-/child_process-1.0.2.tgz", + "integrity": "sha512-Wmza/JzL0SiWz7kl6MhIKT5ceIlnFPJX+lwUGj7Clhy5MMldsSoJR0+uvRzOS5Kv45Mq7t1PoE8TsOA9bzvb6g==" + }, "node_modules/chokidar": { "version": "3.5.3", "dev": true, @@ -5584,7 +5590,6 @@ }, "node_modules/for-each": { "version": "0.3.3", - "dev": true, "license": "MIT", "dependencies": { "is-callable": "^1.1.3" @@ -5616,9 +5621,9 @@ }, "node_modules/fs.realpath": { "version": "1.0.0", - "dev": true, "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", + "dev": true, "license": "ISC" }, "node_modules/function-bind": { @@ -5782,7 +5787,6 @@ }, "node_modules/gopd": { "version": "1.0.1", - "dev": true, "license": "MIT", "dependencies": { "get-intrinsic": "^1.1.3" @@ -5873,7 +5877,6 @@ }, "node_modules/has-tostringtag": { "version": "1.0.0", - "dev": true, "license": "MIT", "dependencies": { "has-symbols": "^1.0.2" @@ -6407,7 +6410,6 @@ }, "node_modules/is-arguments": { "version": "1.1.1", - "dev": true, "license": "MIT", "dependencies": { "call-bind": "^1.0.2", @@ -6477,7 +6479,6 @@ }, "node_modules/is-callable": { "version": "1.2.7", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -6541,6 +6542,20 @@ "node": ">=8" } }, + "node_modules/is-generator-function": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.0.10.tgz", + "integrity": "sha512-jsEjy9l3yiXEQ+PsXdmBwEPcOxaXWLspKdplFUVI9vq1iZgIekeC0L167qeu86czQaxed3q/Uzuw0swL0irL8A==", + "dependencies": { + "has-tostringtag": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-glob": { "version": "4.0.3", "dev": true, @@ -6713,7 +6728,6 @@ }, "node_modules/is-typed-array": { "version": "1.1.10", - "dev": true, "license": "MIT", "dependencies": { "available-typed-arrays": "^1.0.5", @@ -10224,6 +10238,18 @@ "requires-port": "^1.0.0" } }, + "node_modules/util": { + "version": "0.12.5", + "resolved": "https://registry.npmjs.org/util/-/util-0.12.5.tgz", + "integrity": "sha512-kZf/K6hEIrWHI6XqOFUiiMa+79wE/D8Q+NCNAWclkyg3b4d2k7s0QGepNjiABc+aR3N1PAyHL7p6UcLY6LmrnA==", + "dependencies": { + "inherits": "^2.0.3", + "is-arguments": "^1.0.4", + "is-generator-function": "^1.0.7", + "is-typed-array": "^1.1.3", + "which-typed-array": "^1.1.2" + } + }, "node_modules/util-deprecate": { "version": "1.0.2", "license": "MIT" @@ -10670,7 +10696,6 @@ }, "node_modules/which-typed-array": { "version": "1.1.10", - "dev": true, "license": "MIT", "dependencies": { "available-typed-arrays": "^1.0.5", diff --git a/package.json b/package.json index 25e37385..a9b8b3eb 100644 --- a/package.json +++ b/package.json @@ -78,6 +78,7 @@ "dependencies": { "@babel/runtime": "^7.22.6", "bootstrap": "^5.3.2", + "child_process": "^1.0.2", "dotenv": "^16.3.1", "express": "^4.18.2", "helmet": "^7.0.0", @@ -87,6 +88,7 @@ "react-player": "^2.13.0", "react-range": "^1.8.14", "react-slider": "^2.0.6", + "util": "^0.12.5", "winston": "^3.10.0" }, "engines": { diff --git a/server/cronjob.txt b/server/cronjob.txt new file mode 100644 index 00000000..2e81de22 --- /dev/null +++ b/server/cronjob.txt @@ -0,0 +1 @@ +*/10 * * * * /usr/bin/node /server/serverPing.js \ No newline at end of file diff --git a/server/serverPing.js b/server/serverPing.js new file mode 100644 index 00000000..b515ed89 --- /dev/null +++ b/server/serverPing.js @@ -0,0 +1,15 @@ +const child_process = require("child_process"); //to run command-line tools +const util = require("util"); //to handle asynchronous functions + +const exec = util.promisify(child_process.exec); + +async function ping(hostname) { + try { + const { stdout, stderr } = await exec(`ping -c 3 ${hostname}`); + return { stderr, stdout }; + } catch (err) { + return err; + } +} + +ping("starter-kit-al84.onrender.com");