1
0

Compare commits

...

4 Commits

Author SHA1 Message Date
Raito Bezarius
a139a262c1 seedrng: init at 2022.04
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-05 14:18:00 +01:00
6a5fed83dd conditional fetch in json-to-fstree 2024-09-05 11:14:47 +01:00
bcf5ab24e8 tidy watch-outputs startup message 2024-09-05 10:11:16 +01:00
32bf80c6fa devout: unlink socket pathname before binding 2024-09-05 10:05:13 +01:00
4 changed files with 22 additions and 17 deletions

View File

@ -115,6 +115,7 @@ in {
# vendor OS, or even to derisk Liminix updates on that device
schnapps = callPackage ./schnapps { };
seedrng = callPackage ./seedrng {};
serviceFns = callPackage ./service-fns { };
swconfig = callPackage ./swconfig { };
systemconfig = callPackage ./systemconfig { };

View File

@ -131,6 +131,7 @@
(fn unix-socket [name]
(let [addr (string.pack "=Hz" AF_LOCAL name)
fd (check-errno (ll.socket AF_LOCAL SOCK_STREAM 0))]
(os.remove name)
(check-errno (ll.bind fd addr))
(check-errno (ll.listen fd 32))
fd))

View File

@ -4,19 +4,25 @@
(local { : utime } (require :lualinux))
(fn download [url dest]
(match (http.fetch url)
(nil code str)
(assert nil (.. "error " code ": " str))
(let [state (.. dest "/state")
previously (ll.lstat state 12)]
(match (http.fetch url "i" previously)
(nil 10 _) ; not modified
(print (.. url " not modified, already up to date"))
(body { : last-modified })
(let [service (svc.open dest)
lock (.. dest "/.lock")
state (.. dest "/state")]
(with-open [fout (io.open lock :w)] (fout:write ""))
(service:output "." (json.decode body))
(with-open [fout (io.open state :w)] (fout:write "ok"))
(os.remove lock)
(utime dest last-modified))))
(nil code str)
(assert nil (.. "error " code ": " str))
(body { : last-modified })
(let [service (svc.open dest)
lock (.. dest "/.lock")]
(with-open [fout (io.open lock :w)] (fout:write ""))
(service:output "." (json.decode body))
(with-open [fout (io.open state :w)] (fout:write "ok"))
(utime state last-modified)
(os.remove lock))
)))
(fn run [] (download (. arg 1) (. arg 2)))

View File

@ -1,4 +1,4 @@
(local { : system : assoc : split : table= : dig } (require :anoia))
(local { : %% : system : assoc : split : table= : dig } (require :anoia))
(local svc (require :anoia.svc))
(local { : view } (require :fennel))
(local { : kill } (require :lualinux))
@ -27,8 +27,6 @@
_ path (ipairs paths)]
(or changed? (not (table= (dig old-tree path) (dig new-tree path))))))
(fn %% [fmt ...] (string.format fmt ...))
(fn do-action [action service]
(case action
:restart (system (%% "s6-svc -r /run/service/%s" service))
@ -42,9 +40,8 @@
: watched-service
: paths } (parse-args arg)
dir (.. watched-service "/.outputs")
_ (print :service-dir dir)
service (assert (svc.open dir))]
(print "watching " watched-service)
(print (%% "watching %q" watched-service))
(accumulate [tree (service:output ".")
v (service:events)]
(let [new-tree (service:output ".")]