liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

lease-watcher.fnl (572B)


      1 (local { : %% : system } (require :anoia))
      2 (local svc (require :anoia.svc))
      3 
      4 (fn up-service [name]
      5   (system (%% "s6-rc-up-tree %q" name)))
      6 
      7 (fn down-service [name]
      8   (system (%% "s6-rc -b -d change %q" name)))
      9 
     10 (fn react [s controlled]
     11   (let [ip (s:output "ip")]
     12     (print "event" "ip=" ip)
     13     (if ip
     14         (up-service controlled)
     15         (down-service controlled))))
     16 
     17 (fn run []
     18   (let [[watched controlled] arg
     19         s (assert (svc.open watched))]
     20     (print :service s)
     21     (react s controlled)
     22     (each [e (s:events)]
     23       (react s controlled))))
     24 
     25 { : run }