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