ff_olsr_watchdog 672 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/lua
  2. require "os"
  3. require "io"
  4. require "uci"
  5. local fs = require "nixio.fs"
  6. if fs.access("/var/run/olsrd.pid") or fs.access("/var/run/olsrd4.pid") then
  7. local stamp, intv
  8. local x = uci.cursor()
  9. x:foreach("olsrd", "LoadPlugin",
  10. function(s)
  11. if s.library == "olsrd_watchdog.so.0.1" then
  12. intv = tonumber(s.interval)
  13. stamp = s.file
  14. end
  15. end)
  16. if intv and fs.access(stamp) then
  17. local systime = os.time()
  18. local wdgtime = tonumber(io.lines(stamp)())
  19. if not wdgtime or ( systime - wdgtime ) > ( intv * 2 ) then
  20. os.execute("logger -t 'OLSR watchdog' 'Process died - restarting!'")
  21. os.execute("/etc/init.d/olsrd restart")
  22. end
  23. end
  24. end