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 --- Makefile | 44 ++++++++++++++++++++++ README | 1 + config.mk | 10 +++++ postgresql-controller.lua | 26 +++++++++++++ postgresql-details-html.lsp | 17 +++++++++ postgresql-expert-html.lsp | 1 + postgresql-listfiles-html.lsp | 39 ++++++++++++++++++++ postgresql-logfile-html.lsp | 7 ++++ postgresql-model.lua | 86 +++++++++++++++++++++++++++++++++++++++++++ postgresql-startstop-html.lsp | 24 ++++++++++++ postgresql-status-html.lsp | 1 + postgresql.menu | 4 ++ postgresql.roles | 3 ++ 13 files changed, 263 insertions(+) create mode 100644 Makefile create mode 100644 README create mode 100644 config.mk create mode 100644 postgresql-controller.lua create mode 100644 postgresql-details-html.lsp create mode 120000 postgresql-expert-html.lsp create mode 100644 postgresql-listfiles-html.lsp create mode 100644 postgresql-logfile-html.lsp create mode 100644 postgresql-model.lua create mode 100644 postgresql-startstop-html.lsp create mode 120000 postgresql-status-html.lsp create mode 100644 postgresql.menu create mode 100644 postgresql.roles diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b69fe20 --- /dev/null +++ b/Makefile @@ -0,0 +1,44 @@ +APP_NAME=postgresql +PACKAGE=acf-$(APP_NAME) +VERSION=0.1.1 + +APP_DIST=\ + postgresql* \ + + +EXTRA_DIST=README Makefile config.mk + +DISTFILES=$(APP_DIST) $(EXTRA_DIST) + +TAR=tar + +P=$(PACKAGE)-$(VERSION) +tarball=$(P).tar.bz2 +install_dir=$(DESTDIR)/$(appdir)/$(APP_NAME) + +all: +clean: + rm -rf $(tarball) $(P) + +dist: $(tarball) + +install: + mkdir -p "$(install_dir)" + cp -a $(APP_DIST) "$(install_dir)" + +$(tarball): $(DISTFILES) + rm -rf $(P) + mkdir -p $(P) + cp -a $(DISTFILES) $(P) + $(TAR) -jcf $@ $(P) + rm -rf $(P) + +# target that creates a tar package, unpacks is and install from package +dist-install: $(tarball) + $(TAR) -jxf $(tarball) + $(MAKE) -C $(P) install DESTDIR=$(DESTDIR) + rm -rf $(P) + +include config.mk + +.PHONY: all clean dist install dist-install diff --git a/README b/README new file mode 100644 index 0000000..afc7832 --- /dev/null +++ b/README @@ -0,0 +1 @@ +ACF for postgresql diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..45f4d21 --- /dev/null +++ b/config.mk @@ -0,0 +1,10 @@ +prefix=/usr +datadir=${prefix}/share +sysconfdir=${prefix}/etc +localstatedir=${prefix}/var +acfdir=${datadir}/acf +wwwdir=${acfdir}/www +cgibindir=${acfdir}/cgi-bin +appdir=${acfdir}/app +acflibdir=${acfdir}/lib +sessionsdir=${localstatedir}/lib/acf/sessions diff --git a/postgresql-controller.lua b/postgresql-controller.lua new file mode 100644 index 0000000..cf6301f --- /dev/null +++ b/postgresql-controller.lua @@ -0,0 +1,26 @@ +module(..., package.seeall) + +-- Load libraries +require("controllerfunctions") + +default_action = "status" + +function status(self) + return self.model.getstatus() +end + +function startstop(self) + return controllerfunctions.handle_startstop(self, self.model.startstop_service, self.model.getstatus, self.clientdata) +end + +function details(self) + return self.model.getstatusdetails() +end + +function listfiles(self) + return self.model.getfilelist() +end + +function expert(self) + return controllerfunctions.handle_form(self, function() return self.model.getfiledetails(self.clientdata.filename) end, self.model.updatefiledetails, self.clientdata, "Save", "Edit Postgresql File", "File Saved") +end diff --git a/postgresql-details-html.lsp b/postgresql-details-html.lsp new file mode 100644 index 0000000..b8a4ce7 --- /dev/null +++ b/postgresql-details-html.lsp @@ -0,0 +1,17 @@ +<% local data, viewlibrary = ... +require("viewfunctions") +--[[ DEBUG INFORMATION +io.write("

DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(data)) +io.write("
") +--]] +%> + +<% viewlibrary.dispatch_component("status") %> + +

<%= html.html_escape(data.label) %>

+
+<% +displayitem(data) +%> +
diff --git a/postgresql-expert-html.lsp b/postgresql-expert-html.lsp new file mode 120000 index 0000000..207f324 --- /dev/null +++ b/postgresql-expert-html.lsp @@ -0,0 +1 @@ +../expert-html.lsp \ No newline at end of file diff --git a/postgresql-listfiles-html.lsp b/postgresql-listfiles-html.lsp new file mode 100644 index 0000000..f94653b --- /dev/null +++ b/postgresql-listfiles-html.lsp @@ -0,0 +1,39 @@ +<% local data, viewlibrary, page_info, session = ... +require("viewfunctions") +%> +<% +--[[ DEBUG INFORMATION +io.write("

DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(data)) +io.write("
") +--]] +%> + +<% displaycommandresults({"expert", "startstop"}, session) %> + +<% if viewlibrary and viewlibrary.dispatch_component then + viewlibrary.dispatch_component("status") +end %> + +

<%= html.html_escape(data.label) %>

+ + + + + + + + + +<% for i,file in ipairs(data.value) do %> + + + + + +<% end %> +
FileSizeLast Modified
<%= html.link{value = "expert?filename=" .. file.filename.."&redir="..page_info.orig_action, label=file.filename} %><%= html.html_escape(file.filesize) %><%= html.html_escape(file.mtime) %>
+ +<% if viewlibrary and viewlibrary.dispatch_component then + viewlibrary.dispatch_component("startstop") +end %> diff --git a/postgresql-logfile-html.lsp b/postgresql-logfile-html.lsp new file mode 100644 index 0000000..4f2e388 --- /dev/null +++ b/postgresql-logfile-html.lsp @@ -0,0 +1,7 @@ +<% local data, viewlibrary = ... +require("viewfunctions") +%> + +<% if viewlibrary and viewlibrary.dispatch_component then + viewlibrary.dispatch_component("alpine-baselayout/logfiles/view", {name="/var/log/messages", grep="postgres"}) +end %> 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 diff --git a/postgresql-startstop-html.lsp b/postgresql-startstop-html.lsp new file mode 100644 index 0000000..dbecda9 --- /dev/null +++ b/postgresql-startstop-html.lsp @@ -0,0 +1,24 @@ +<% local data, viewlibrary, page_info = ... %> + +

Management

+
+
" method="POST"> +
Program control-panel
+
+> +> +> +> +
+
+ +<% if data.value.result then %> +
Previous action result
+
+<% if data.value.result.value ~= "" then %> +

<%= string.gsub(html.html_escape(data.value.result.value), "\n", "
") %>

+<% end if data.value.result.errtxt then %> +

<%= string.gsub(html.html_escape(data.value.result.errtxt), "\n", "
") %>

+<% end end %> +
+
diff --git a/postgresql-status-html.lsp b/postgresql-status-html.lsp new file mode 120000 index 0000000..b2f8480 --- /dev/null +++ b/postgresql-status-html.lsp @@ -0,0 +1 @@ +../status-html.lsp \ No newline at end of file diff --git a/postgresql.menu b/postgresql.menu new file mode 100644 index 0000000..d864964 --- /dev/null +++ b/postgresql.menu @@ -0,0 +1,4 @@ +#CAT GROUP/DESC TAB ACTION +Applications 60Postgresql Status status +Applications 60Postgresql Expert listfiles +Applications 60Postgresql Logfile logfile diff --git a/postgresql.roles b/postgresql.roles new file mode 100644 index 0000000..8e3f58e --- /dev/null +++ b/postgresql.roles @@ -0,0 +1,3 @@ +USER=postgresql:status,postgresql:logfile,postgresql:details,postgresql:startstop +EXPERT=postgresql:listfiles,postgresql:expert +ADMIN=postgresql:status,postgresql:logfile,postgresql:details,postgresql:startstop,postgresql:listfiles,postgresql:expert -- cgit v1.2.3