liminix

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

odhcp6-script.fnl (1481B)


      1 
      2 (local state-directory (assert (os.getenv "SERVICE_STATE")))
      3 (os.execute (.. "mkdir -p " state-directory))
      4 
      5 (fn write-value [name value]
      6   (let [path (.. state-directory "/" name)]
      7     (with-open [fout (io.open path :w)]
      8       (when value (fout:write value)))))
      9 
     10 (fn write-value-from-env [name]
     11   (write-value name (os.getenv (string.upper name))))
     12 
     13 ;; we remove state before updating to ensure that consumers don't get
     14 ;; a half-updated snapshot
     15 (os.remove (.. state-directory "/state"))
     16 
     17 (let [wanted
     18       [
     19        :addresses
     20        :aftr
     21        :cer
     22        :domains
     23        :lw406
     24        :mape
     25        :mapt
     26        :ntp_fqdn
     27        :ntp_ip
     28        :option_1
     29        :option_2
     30        :option_3
     31        :option_4
     32        :option_5
     33        :passthru
     34        :prefixes
     35        :ra_addresses
     36        :ra_dns
     37        :ra_domains
     38        :ra_hoplimit
     39        :ra_mtu
     40        :ra_reachable
     41        :ra_retransmit
     42        :ra_routes
     43        :rdnss
     44        :server
     45        :sip_domain
     46        :sip_ip
     47        :sntp_ip
     48        :sntp_fqdn
     49        ]]
     50   (each [_ n (ipairs wanted)]
     51     (write-value-from-env n)))
     52 
     53 (let [[ifname state] arg
     54       ready (match state
     55               "started" false
     56               "unbound" false
     57               "stopped" false
     58               _ true)]
     59   (write-value ".lock" (tostring (os.time)))
     60   (write-value "ifname" ifname)
     61   (write-value "state" state)
     62   (os.remove (.. state-directory "/.lock"))
     63   (when ready
     64     (with-open [fd (io.open "/proc/self/fd/10" :w)] (fd:write "\n"))))