Commit 64a4cac9 authored by Ted Trask's avatar Ted Trask
Browse files

Added postgresql first cut.

git-svn-id: svn://svn.alpinelinux.org/acf/postgresql/trunk@1726 ab2d0c66-481e-0410-8bed-d214d4d58bed
parents
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
ACF for postgresql
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
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
<% local data, viewlibrary = ...
require("viewfunctions")
--[[ DEBUG INFORMATION
io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
io.write(html.cfe_unpack(data))
io.write("</span>")
--]]
%>
<% viewlibrary.dispatch_component("status") %>
<H2><%= html.html_escape(data.label) %></H2>
<DL>
<%
displayitem(data)
%>
</DL>
../expert-html.lsp
\ No newline at end of file
<% local data, viewlibrary, page_info, session = ...
require("viewfunctions")
%>
<%
--[[ DEBUG INFORMATION
io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
io.write(html.cfe_unpack(data))
io.write("</span>")
--]]
%>
<% displaycommandresults({"expert", "startstop"}, session) %>
<% if viewlibrary and viewlibrary.dispatch_component then
viewlibrary.dispatch_component("status")
end %>
<h1><%= html.html_escape(data.label) %></h1>
<TABLE>
<TR style="background:#eee;font-weight:bold;">
<TD style="padding-right:20px;white-space:nowrap;text-align:left;" class="header">File</TD>
<TD style="padding-right:20px;white-space:nowrap;text-align:left;" class="header">Size</TD>
<TD style="white-space:nowrap;text-align:left;" class="header">Last Modified</TD>
</TR>
<% for i,file in ipairs(data.value) do %>
<TR>
<TD style="padding-right:20px;white-space:nowrap;"><%= html.link{value = "expert?filename=" .. file.filename.."&redir="..page_info.orig_action, label=file.filename} %></TD>
<TD style="padding-right:20px;white-space:nowrap;"><%= html.html_escape(file.filesize) %></TD>
<TD style="white-space:nowrap;" width="90%"><%= html.html_escape(file.mtime) %></TD>
</TR>
<% end %>
</TABLE>
<% if viewlibrary and viewlibrary.dispatch_component then
viewlibrary.dispatch_component("startstop")
end %>
<% 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 %>
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
<% local data, viewlibrary, page_info = ... %>
<H1>Management</H1>
<DL>
<form action="<%= html.html_escape(page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action) %>" method="POST">
<DT>Program control-panel</DT>
<DD>
<input class="submit" type="submit" name="action" value="Setup" <% if data.value.status.value== "Running" then io.write("disabled") end %>>
<input class="submit" type="submit" name="action" value="Start" <% if data.value.status.value== "Running" then io.write("disabled") end %>>
<input class="submit" type="submit" name="action" value="Stop" <% if data.value.status.value== "Stopped" then io.write("disabled") end %>>
<input class="submit" type="submit" name="action" value="Restart" <% if data.value.status.value== "Stopped" then io.write("disabled") end %>>
</DD>
</form>
<% if data.value.result then %>
<DT>Previous action result</DT>
<DD>
<% if data.value.result.value ~= "" then %>
<P CLASS='descr'><%= string.gsub(html.html_escape(data.value.result.value), "\n", "<BR>") %></P>
<% end if data.value.result.errtxt then %>
<P CLASS='error'><%= string.gsub(html.html_escape(data.value.result.errtxt), "\n", "<BR>") %></P>
<% end end %>
</DD>
</DL>
../status-html.lsp
\ No newline at end of file
#CAT GROUP/DESC TAB ACTION
Applications 60Postgresql Status status
Applications 60Postgresql Expert listfiles
Applications 60Postgresql Logfile logfile
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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment