From 851a90283fdc05e48b1d0e94252b6d33d7d4261f Mon Sep 17 00:00:00 2001 From: Patrick McDonagh Date: Wed, 3 Feb 2016 10:26:40 -0600 Subject: [PATCH] Added functions to check loggers and restart loggers --- init/loggers | 6 +++--- www/functions_SQLite.js | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/init/loggers b/init/loggers index f89a557..58c4809 100755 --- a/init/loggers +++ b/init/loggers @@ -21,14 +21,14 @@ case "$1" in # run application you want to start #python /home/poconsole/src/dataLogger/alarmLogger.py & #python /home/poconsole/src/dataLogger/dataLogger.py & - /usr/bin/python /home/poconsole/tagserver/python/tagserver_SQLite.py > /dev/null 2>&1 & echo $! > "/root/solar_ww.pid" + /usr/bin/python /home/poconsole/tagserver/python/tagserver_SQLite.py > /dev/null 2>&1 & echo $! > "/root/tagserver.pid" ;; stop) echo "Stopping loggers" # kill application you want to stop #killall python - kill -9 $(cat /root/solar_ww.pid) + kill -9 $(cat /root/tagserver.pid) ;; *) @@ -37,4 +37,4 @@ case "$1" in ;; esac -exit 0 +exit 0 diff --git a/www/functions_SQLite.js b/www/functions_SQLite.js index ca9ebde..e470dfb 100644 --- a/www/functions_SQLite.js +++ b/www/functions_SQLite.js @@ -277,3 +277,28 @@ exports.latestValueAllTags = function(req, res){ }); }); }; + +exports.checkLoggerStatus = function(req, res){ + var fs = require('fs'); + // var ps = require("ps-node"); + var running = require("is-running"); + fs.readFile('/root/dataLogger.pid', function (derr,ddata) { + if (derr) { + console.log("Problem getting PID of tagserver"); + res.json({status:"error", message: "Problem getting PID of tagserver"}); + } else { + res.json({status: "OK", running: running(ddata)}); + } + }); +}; + +exports.restartLogger = function(req, res){ + var exec = require('child_process').exec; + exec('/etc/init.d/loggers start', function(error, stdout, stderr){ + if (error){ + res.json({status:"error", message:error}); + } else { + res.json({status:"OK"}); + } + }); +};