Should complete POCONSOLE-77 for reading datalogger status and restarting

This commit is contained in:
Patrick McDonagh
2016-12-05 16:46:48 -06:00
parent f8a0345c3a
commit b3e297f26b
4 changed files with 35 additions and 14 deletions

View File

@@ -1,5 +1,6 @@
import os
import subprocess
from flask import Flask, render_template, request, session, send_from_directory, jsonify, url_for, flash, redirect, Response
from werkzeug.utils import secure_filename
from sqlalchemy import and_, desc
@@ -13,6 +14,7 @@ from pycomm_helper.utils import readTag, writeTag
from random import random
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif', 'doc', 'docx', 'xls', 'xlsx', 'zip'])
PID_FILE = '/root/datalogger.pid'
def allowed_file(filename):
@@ -277,3 +279,28 @@ def restore_single(id):
except:
print("Error backing up tag value for tag {}".format(single_br['tag']))
return jsonify(single_br)
@app.route('/api/logger_status')
def get_logger_status():
global PID_FILE
try:
with open(PID_FILE, 'rb') as pidfile:
pid = f.read()
os.kill(pid, 0)
except OSError:
return jsonify(False)
except IOError:
return jsonify(False)
else:
return jsonify(True)
@app.route('/api/restart_logger')
def restart_datalogger():
global PID_FILE
try:
subprocess.call(["service", "datalogger", "restart"], shell=False)
except Exception as e:
print("Exception during restart_datalogger: {}".format(e))
return get_logger_status()

View File

@@ -49,15 +49,15 @@ poconsole.controller('configCtrl', function($scope, Page, $log, Config, Device,
var checkLoggerStatus = Config.getLoggerStatus();
checkLoggerStatus.then(function(data){
$scope.loggerLoading = false;
$scope.loggerRunning = data.status;
$scope.loggerRunning = data;
});
};
// $scope.checkLogger();
$scope.checkLogger();
$scope.restartLogger = function(){
var restartLogger = Config.restartLogger();
restartLogger.then(function(data){
$scope.checkLogger();
console.log(data);
});
};

View File

@@ -48,26 +48,20 @@ poconsole.factory('Config',function($q, $http, $log){
config.getLoggerStatus = function(){
var deferred = $q.defer();
$http.get('/logger_status').success(function(data) {
deferred.resolve({
pid:data.pid,
status: data.status
});
$http.get('/api/logger_status').success(function(data) {
deferred.resolve(JSON.parse(data));
});
return deferred.promise;
};
config.restartLogger = function(){
var deferred = $q.defer();
$http.get('/restart_logger').success(function(data) {
deferred.resolve({
data: data
});
$http.get('/api/restart_logger').success(function(data) {
deferred.resolve(data);
});
return deferred.promise;
};
return config;
});

View File

@@ -58,7 +58,7 @@ case "$1" in
uninstall)
uninstall
;;
retart)
restart)
stop
start
;;