restart-services.fnl (1281B)
1 (fn hashes-from-file [name] 2 (with-open [f (assert (io.open name :r) name)] 3 (accumulate [h [] 4 l #(f:read "*l")] 5 (let [(name hash) (string.match l "([^%s]+) +([^%s]+)")] 6 (if name 7 (doto h (tset name hash)) 8 h))))) 9 10 (fn write-restarts [old new] 11 (let [old-hashes (hashes-from-file old) 12 new-hashes (hashes-from-file new)] 13 (with-open [f (io.open "/tmp/restarts" :w)] 14 (each [n h (pairs old-hashes)] 15 (let [new (. new-hashes n)] 16 (when (or (= h "force-restart") 17 (= new "force-restart") 18 (not (= h new))) 19 (f:write (.. n " restart\n")))))))) 20 21 (fn exec [text command] 22 (io.write (.. text ": ")) 23 (match (os.execute command) 24 res (print "[OK]") 25 (nil err) (error (.. "[FAILED " err "]")))) 26 27 (let [mypath (: (. arg 0) :match "(.*/)") 28 activate (.. mypath "activate /") 29 old-compiled "/run/s6-rc/compiled/" 30 new-compiled "/etc/s6-rc/compiled/"] 31 32 (exec "installing FHS files" activate) 33 34 (write-restarts (.. old-compiled "hashes") (.. new-compiled "hashes")) 35 36 (exec "updating service database" 37 (.. "s6-rc-update -f /tmp/restarts " new-compiled)) 38 39 (exec "starting services" (.. "s6-rc -u -p change default")) 40 )