Skip to content

Commit

Permalink
systemRestart call, closes #134
Browse files Browse the repository at this point in the history
  • Loading branch information
miopa committed May 10, 2017
1 parent 647c3c9 commit e953a6d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
26 changes: 26 additions & 0 deletions myLib.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
var emailjs = require("emailjs");
var mailConfig = require("./etc/email.json");
var child_process = require('child_process');

function sysExec(path, args, cb) {
console.log('appExec', path, args);
let app = child_process.spawn(path, args);
let output = '';
app.on('close', (code) => {
if (code !== 0) {
console.error(`process exited with code ${code}`);
cb(code, output);
} else {
cb(null, output);
}
});
app.on('error', (err) => {
console.error(`Failed to start child process. ${err}`);
});
app.stdout.on('data', (data) => {
output += data;
});

app.stderr.on('data', (data) => {
output += data;
});
};

function mailSend(subject, body, addressTo) {
var server = emailjs.server.connect({
Expand Down Expand Up @@ -140,3 +165,4 @@ exports.msecDuration = function(hms) {
var a = hms.split(':'); // split it at the colons
return ((+a[0]) * 60 * 60 + (+a[1]) * 60 + (+a[2])) * 1000;
};
exports.sysExec = sysExec;
7 changes: 6 additions & 1 deletion rest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

var myLib = require("./myLib");
var userApi = require("./userApi");
var ami = require("./ami");
Expand All @@ -25,6 +24,12 @@ var resetDongle = function (dongleName, reason) {
}
};

exports.systemRestart = function (params, reply) {
myLib.sysExec("/usr/bin/sudo", ["/usr/bin/shutdown", "-r", "now"], (err, output) => {
reply(err ? 503 : 200, output);
});
};

exports.resetModems = function (params, reply) {
if (params.name) {
if (s.ui.mixer.channels[params.name] && s.ui.mixer.channels[params.name].mode !== 'defunct') {
Expand Down

0 comments on commit e953a6d

Please sign in to comment.