Skip to content
Snippets Groups Projects
Unverified Commit 38d6f75d authored by J. Burfeind's avatar J. Burfeind Committed by GitHub
Browse files

gluon-state-check: implement state checker (#2245)

parent d3d22ba6
No related branches found
No related tags found
No related merge requests found
include $(TOPDIR)/rules.mk
PKG_NAME:=gluon-state-check
PKG_VERSION:=1
include ../gluon.mk
define Package/gluon-state-check
TITLE:=Provides info about the routers state
DEPENDS:=+gluon-core +micrond
endef
define Package/gluon-state-check/description
gluon-state-check executes checks in `/lib/gluon/state/check.d/` and provides
a flag file for each check in `/var/gluon/state` depending on the return code
of the check. A flag file is created (or "touched") if the corresponding check
exits cleanly and gets removed otherwise. If the flags are "touched", they
are only accessed, but not modified. In this way, the atime of a flag file
reflects when the last check was performed and the mtime reflects when
when the state was last changed.
This package provides the following checks:
- `has_default_gw6` - check whether the router has a default IPv6-route on br-client.
The checks are executed once every minute (by micron.d).
endef
$(eval $(call BuildPackageGluon,gluon-state-check))
#!/bin/sh
out=$(ip -6 route show default dev br-client 2>/dev/null) && [ -n "$out" ]
* * * * * /usr/sbin/gluon-state-check
#!/usr/bin/lua
local util = require 'gluon.util'
local unistd = require 'posix.unistd'
local state_dir = "/var/gluon/state/"
local check_dir = "/lib/gluon/state/check.d/"
local function set_flag(stateflag, state)
if state then
-- this does not modify atime
local flaghandle = io.open(stateflag, "w")
flaghandle:close()
else
os.remove(stateflag)
end
end
local function exec_check(checkpath)
local checkname = string.sub(checkpath, #check_dir+1)
local ret = os.execute(checkpath)
local flagfile = state_dir..checkname
set_flag(flagfile, 0==ret)
end
local function run_executable_checks()
for _, v in ipairs(util.glob(check_dir..'*')) do
if unistd.access(v, 'x') then
exec_check(v)
end
end
end
-- ensure state path exists
if not unistd.access(state_dir) then
os.execute("mkdir -p "..state_dir)
end
run_executable_checks()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment