summaryrefslogtreecommitdiffstats
path: root/postgresql-model.lua
blob: 1c492f342ebf4eeaee296689b7a898f5f3eb4c30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
module(..., package.seeall)

-- Load libraries
modelfunctions = require("modelfunctions")
fs = require("acf.fs")
format = require("acf.format")

-- Set variables
local confdfile = "/etc/conf.d/postgresql"
local processname = "postgresql"
local packagename = "postgresql"

local path = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin "

local datadirectory
local filelist

function set_processname(p)
	processname = p
	confdfile = "/etc/conf.d/"..processname
end

-- ################################################################################
-- LOCAL FUNCTIONS

local determinefilelist = function()
	if not filelist then
		datadirectory = format.get_ini_entry(fs.read_file(confdfile) or "", "", "PGDATA")
		filelist = fs.find_files_as_array(".*%.conf", datadirectory)
	end
	return filelist
end

-- ################################################################################
-- PUBLIC FUNCTIONS

function get_startstop(self, clientdata)       
	return modelfunctions.get_startstop(processname)
end

function startstop_service(self, startstop, action)
	return modelfunctions.startstop_service(startstop, action)
end

function getstatus()
	return modelfunctions.getstatus(processname, packagename, "Postgresql Status")
end

function getstatusdetails()
	return cfe({ type="longtext", value="", label="Postgresql Status Details" })
end

function getfilelist()
	local listed_files = {}

	for i,name in ipairs(determinefilelist()) 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, determinefilelist())
end

function updatefiledetails(self, filedetails)
	return modelfunctions.setfiledetails(self, filedetails, determinefilelist())
end