From 84d0b69725b4b0d4f894aaa85bea7819a384afba Mon Sep 17 00:00:00 2001 From: Michele Marcucci Date: Tue, 6 Nov 2018 19:04:47 +0100 Subject: [PATCH] Added fake actions for mcu stats, reboot, shutdown --- scripts/os_stats | 1 + scripts/os_stats_fake | 33 ++++++++++++++++++++++ src/graphql/graphqlModules/Mcu/McuStats.js | 1 + src/store/api/mcu/mcuReboot.js | 3 +- src/store/api/mcu/mcuShutdown.js | 3 +- src/store/api/mcu/mcuStats.js | 3 +- 6 files changed, 41 insertions(+), 3 deletions(-) create mode 100755 scripts/os_stats_fake diff --git a/scripts/os_stats b/scripts/os_stats index 8a9b1fe..2ec7a97 100755 --- a/scripts/os_stats +++ b/scripts/os_stats @@ -62,6 +62,7 @@ JSON="{ \"memory\": { \"total\": $memTotal, + \"available\": $memAvailable, \"used\": $memUsed, \"cache\": $memCached, \"swap\": $swapUsed diff --git a/scripts/os_stats_fake b/scripts/os_stats_fake new file mode 100755 index 0000000..155eef2 --- /dev/null +++ b/scripts/os_stats_fake @@ -0,0 +1,33 @@ +#!/bin/bash + +cat << EOF +{ + "hostname": "orangepizero", + "operatingSystem": "Ubuntu 18.04 bionic", + "uptime": "2018-11-06 14:01:22", + "loadAverage": "0.00 0.00 0.00 1/120 2859", + "architecture": "armv7l", + "temperature": "40656", + "memory": + { + "total": 245760, + "available": 127384, + "used": 207276, + "cache": 90348, + "swap": 256 + }, + "cpu": + { + "threads": 4, + "usedPercent": 0 + }, + "disks": [ + {"total":7678936, +"used":1468092, +"mountPoint":"/"}, +{"total":49584, +"used":4312, +"mountPoint":"/var/log"} + ] +} +EOF diff --git a/src/graphql/graphqlModules/Mcu/McuStats.js b/src/graphql/graphqlModules/Mcu/McuStats.js index 062e52e..435aeb0 100644 --- a/src/graphql/graphqlModules/Mcu/McuStats.js +++ b/src/graphql/graphqlModules/Mcu/McuStats.js @@ -27,6 +27,7 @@ module.exports.typeDefs = ` type MemoryStats { total: Float + available: Float used: Float cache: Float swap: Float diff --git a/src/store/api/mcu/mcuReboot.js b/src/store/api/mcu/mcuReboot.js index 34d472d..468c115 100644 --- a/src/store/api/mcu/mcuReboot.js +++ b/src/store/api/mcu/mcuReboot.js @@ -2,7 +2,8 @@ const { exec } = require('child_process') module.exports = ({ define }) => { define('reboot', async (payload, { knex, errors, utils }) => { - exec('sudo shutdown -r now') + if (process.env.NODE_ENV === 'production') return exec('sudo shutdown -r now'); + return; }, { auth: true }) diff --git a/src/store/api/mcu/mcuShutdown.js b/src/store/api/mcu/mcuShutdown.js index d00772d..91352a8 100644 --- a/src/store/api/mcu/mcuShutdown.js +++ b/src/store/api/mcu/mcuShutdown.js @@ -2,7 +2,8 @@ const { exec } = require('child_process') module.exports = ({ define }) => { define('shutdown', async (payload, { knex, errors, utils }) => { - exec('sudo shutdown now') + if (process.env.NODE_ENV === 'production') return exec('sudo shutdown now') + return; }, { auth: true }) diff --git a/src/store/api/mcu/mcuStats.js b/src/store/api/mcu/mcuStats.js index b265681..0b3709a 100644 --- a/src/store/api/mcu/mcuStats.js +++ b/src/store/api/mcu/mcuStats.js @@ -13,7 +13,8 @@ module.exports = ({ define }) => { function getOsStats () { return new Promise((resolve, reject) => { - const scriptPath = join(__dirname, '..', '..', '..', '..', 'scripts', 'os_stats') + const scriptName = (process.env.NODE_ENV === 'production') ? 'os_stats' : 'os_stats_fake' + const scriptPath = join(__dirname, '..', '..', '..', '..', 'scripts', scriptName) exec(scriptPath, {}, (err, stdout) => { if (err) { reject(err)