From ded7b7183f7d975776766dda66becd6b85d3d588 Mon Sep 17 00:00:00 2001 From: Kuoi Date: Tue, 30 May 2023 07:26:10 +0800 Subject: [PATCH] add: monitor --- rosa.service | 8 ++++++++ rosa.watch.lua | 30 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 rosa.service create mode 100644 rosa.watch.lua diff --git a/rosa.service b/rosa.service new file mode 100644 index 0000000..dc469db --- /dev/null +++ b/rosa.service @@ -0,0 +1,8 @@ +[Unit] +Description=Rosa API generator +[Service] +Type=simple +ExecStart=/usr/bin/lua /usr/share/lilac/Rosa/rosa.watch.lua +[Install] +WantedBy=multi-user.target + diff --git a/rosa.watch.lua b/rosa.watch.lua new file mode 100644 index 0000000..d83a841 --- /dev/null +++ b/rosa.watch.lua @@ -0,0 +1,30 @@ +#!/usr/bin/lua + +local lfs = require("lfs") + +local rosalua = "/usr/share/lilac/Rosa/rosa.lua" +local filepath = "/usr/share/lilac/Repo/x86_64/bioarchlinux.files" -- what I watch +local last_modified = nil +local attr = lfs.attributes(filepath) +last_modified = attr.modification + +--watch file-- +local function check_changes() + -- current time + local attr = lfs.attributes(filepath) + local current_modified = attr.modification + -- if different + if current_modified ~= last_modified then + -- update info + last_modified = current_modified + -- run script + print("Executing Rosa Lua") + dofile(rosalua) + end +end + +--2 min sync-- +while true do + check_changes() + os.execute("sleep " .. tonumber(120)) -- 120s = 2min +end