gluon-state-check: implement state checker (#2245)
This commit is contained in:
parent
d3d22ba677
commit
38d6f75dd3
28
package/gluon-state-check/Makefile
Normal file
28
package/gluon-state-check/Makefile
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
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))
|
2
package/gluon-state-check/files/lib/gluon/state/check.d/has_default_gw6
Executable file
2
package/gluon-state-check/files/lib/gluon/state/check.d/has_default_gw6
Executable file
@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
out=$(ip -6 route show default dev br-client 2>/dev/null) && [ -n "$out" ]
|
@ -0,0 +1 @@
|
|||||||
|
* * * * * /usr/sbin/gluon-state-check
|
41
package/gluon-state-check/luasrc/usr/sbin/gluon-state-check
Executable file
41
package/gluon-state-check/luasrc/usr/sbin/gluon-state-check
Executable file
@ -0,0 +1,41 @@
|
|||||||
|
#!/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()
|
Loading…
Reference in New Issue
Block a user