test ArchiveEngine monitor
alarm if engine is not running
This commit is contained in:
5
iocBoot/iocarchivemon/Makefile
Normal file
5
iocBoot/iocarchivemon/Makefile
Normal file
@ -0,0 +1,5 @@
|
||||
TOP = ../..
|
||||
include $(TOP)/configure/CONFIG
|
||||
ARCH = linux-x86_64
|
||||
TARGETS = envPaths
|
||||
include $(TOP)/configure/RULES.ioc
|
18
iocBoot/iocarchivemon/st.cmd
Executable file
18
iocBoot/iocarchivemon/st.cmd
Executable file
@ -0,0 +1,18 @@
|
||||
#!../../bin/linux-x86_64/softIocPy2.6
|
||||
|
||||
< envPaths
|
||||
|
||||
dbLoadDatabase("../../dbd/softIocPy.dbd",0,0)
|
||||
softIocPy_registerRecordDeviceDriver(pdbbase)
|
||||
|
||||
py "import logging"
|
||||
py "logging.basicConfig(level=logging.INFO)"
|
||||
|
||||
epicsEnvSet("BASE","/var/cache/channelarchiver")
|
||||
epicsEnvSet("PPAT","The original process ID was ([0-9]+)")
|
||||
|
||||
dbLoadRecords("../../db/pidmon.db","N=ACC-CT{Bck}General-I,SCAN=10 second,FILE=$(BASE)/general/archive_active.lck,PAT=$(PAT)")
|
||||
|
||||
iocInit()
|
||||
|
||||
dbl > records.dbl
|
13
pidMonApp/Makefile
Normal file
13
pidMonApp/Makefile
Normal file
@ -0,0 +1,13 @@
|
||||
TOP=..
|
||||
include $(TOP)/configure/CONFIG
|
||||
include $(TOP)/configure/CONFIG_PY
|
||||
#----------------------------------------
|
||||
# ADD MACRO DEFINITIONS AFTER THIS LINE
|
||||
|
||||
DB += pidmon.db
|
||||
PY += pidmon.py
|
||||
|
||||
include $(TOP)/configure/RULES
|
||||
include $(TOP)/configure/RULES_PY
|
||||
#----------------------------------------
|
||||
# ADD RULES AFTER THIS LINE
|
8
pidMonApp/pidmon.db
Normal file
8
pidMonApp/pidmon.db
Normal file
@ -0,0 +1,8 @@
|
||||
record(stringin, "$(N)") {
|
||||
field(DTYP, "Python Device")
|
||||
field(INP , "@pidmon")
|
||||
field(SCAN, "$(SCAN=)")
|
||||
field(FLNK, "$(FLNK=)")
|
||||
info("pidfile", "$(FILE)")
|
||||
info("pidpat", "$(PAT=)")
|
||||
}
|
63
pidMonApp/pidmon.py
Normal file
63
pidMonApp/pidmon.py
Normal file
@ -0,0 +1,63 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
import re, os, errno
|
||||
|
||||
from devsup import MAJOR_ALARM, READ_ALARM
|
||||
|
||||
class PIDMon(object):
|
||||
def __init__(self, rec, lnk):
|
||||
self.fname = rec.info('pidfile')
|
||||
pat = rec.info('pidpat',None)
|
||||
if not pat:
|
||||
pat = '([1-9]+)'
|
||||
LOG.info('%s: in %s find "%s"', rec.NAME, self.fname, pat)
|
||||
self.pat = re.compile(pat)
|
||||
|
||||
def detach(self, rec):
|
||||
pass
|
||||
def allowScan(self, rec):
|
||||
return False
|
||||
def process(self, rec, reason=None):
|
||||
try:
|
||||
ok, pid = False, None
|
||||
|
||||
LOG.debug('Open %s', self.fname)
|
||||
with open(self.fname, 'r') as F:
|
||||
for line in map(str.rstrip, F.readlines()):
|
||||
LOG.debug('Read: %s', line)
|
||||
M = self.pat.match(line)
|
||||
if M:
|
||||
LOG.debug('Match: %s', M.groups())
|
||||
pid = int(M.group(1))
|
||||
break
|
||||
|
||||
if pid is None:
|
||||
rec.VAL = 'no PID in PID file'
|
||||
return
|
||||
|
||||
LOG.debug('Testing PID %d', pid)
|
||||
os.kill(pid, 0) # 0 doesn't signal, but does check for existance
|
||||
|
||||
rec.VAL = 'Running'
|
||||
ok = True
|
||||
|
||||
except IOError as e:
|
||||
if e.errno==errno.ENOENT:
|
||||
rec.VAL = 'No PID file'
|
||||
else:
|
||||
rec.VAL = str(e)
|
||||
|
||||
except OSError as e:
|
||||
if e.errno==errno.ESRCH:
|
||||
rec.VAL = 'Process not running'
|
||||
else:
|
||||
rec.VAL = str(e)
|
||||
|
||||
finally:
|
||||
if not ok:
|
||||
rec.setSevr(MAJOR_ALARM, READ_ALARM)
|
||||
|
||||
build = PIDMon
|
Reference in New Issue
Block a user