Added fake actions for mcu stats, reboot, shutdown

This commit is contained in:
Michele Marcucci 2018-11-06 19:04:47 +01:00
parent 2dbcfe297c
commit 84d0b69725
6 changed files with 41 additions and 3 deletions

View File

@ -62,6 +62,7 @@ JSON="{
\"memory\":
{
\"total\": $memTotal,
\"available\": $memAvailable,
\"used\": $memUsed,
\"cache\": $memCached,
\"swap\": $swapUsed

33
scripts/os_stats_fake Executable file
View File

@ -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

View File

@ -27,6 +27,7 @@ module.exports.typeDefs = `
type MemoryStats {
total: Float
available: Float
used: Float
cache: Float
swap: Float

View File

@ -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
})

View File

@ -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
})

View File

@ -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)