From 64a4cac9126cb6d79fc243cdb65ae22e6c3d6350 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Tue, 3 Mar 2009 21:55:09 +0000 Subject: Added postgresql first cut. git-svn-id: svn://svn.alpinelinux.org/acf/postgresql/trunk@1726 ab2d0c66-481e-0410-8bed-d214d4d58bed --- postgresql-model.lua | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 postgresql-model.lua (limited to 'postgresql-model.lua') diff --git a/postgresql-model.lua b/postgresql-model.lua new file mode 100644 index 0000000..5ea63a0 --- /dev/null +++ b/postgresql-model.lua @@ -0,0 +1,86 @@ +module(..., package.seeall) + +-- Load libraries +require("modelfunctions") +require("fs") +require("format") + +-- Set variables +local processname = "postgresql" +local packagename = "postgresql" +local datadirectory = "/var/lib/postgresql/data/" +local pidfile = "postmaster.pid" + +local path = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin " + +local filelist = fs.find_files_as_array(".*\.conf", datadirectory) + +-- ################################################################################ +-- LOCAL FUNCTIONS + +-- ################################################################################ +-- PUBLIC FUNCTIONS + +function startstop_service(action) + -- Custom startstop to enable setup option + local result = cfe({ label="Start/Stop result" }) + + if (string.lower(action) == "start") or (string.lower(action) == "stop") or (string.lower(action) == "restart") or (string.lower(action) == "setup") then + local file = io.popen(path .. "/etc/init.d/" .. processname .. " " .. string.lower(action) .. " 2>&1" ) + if file ~= nil then + result.value = file:read( "*a" ) or "" + file:close() + end + posix.sleep(2)-- Wait for the process to start|stop + else + result.errtxt = "Unknown command!" + end + + return result +end + +function getstatus() + local status = modelfunctions.getstatus(processname, packagename, "Postgresql Status") + + -- Enabled status is unique for postgresql + -- Look for pid file stored in data_directory .. /postmaster.pid + local file = datadirectory .. pidfile + -- check to see if there's a matching proc directory and that it was created slightly after the pid file + -- this allows us to avoid the problem with proc numbers wrapping + local tmp = string.match(fs.read_file(file) or "", "%d+") + if tmp then + local dir = "/proc/" .. tmp + filetime = posix.stat(file, "ctime") + dirtime = posix.stat(dir, "ctime") + if dirtime and (tonumber(dirtime) - tonumber(filetime) < 100) then + status.value.status.value = "Running" + end + end + + return status +end + +function getstatusdetails() + return cfe({ type="longtext", value="", label="Postgresql Status Details" }) +end + +function getfilelist() + local listed_files = {} + + for i,name in ipairs(filelist) do + local filedetails = fs.stat(name) or {} + table.insert ( listed_files , {filename=name, mtime=filedetails.mtime or "---", filesize=filedetails.size or "0"} ) + end + + table.sort(listed_files, function (a,b) return (a.filename < b.filename) end ) + + return cfe({ type="list", value=listed_files, label="Postgresql File List" }) +end + +function getfiledetails(filename) + return modelfunctions.getfiledetails(filename, filelist) +end + +function updatefiledetails(filedetails) + return modelfunctions.setfiledetails(filedetails, filelist) +end -- cgit v1.2.3