From ea59dcbdbed15ca5bd60f50cd8107451e74928dd Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Sat, 11 Oct 2008 12:57:42 +0000 Subject: Added rc controller to alpine-baselayout and rc functionality to processinfo library. Changed status Enabled/Disabled to Running/Stopped. Added links to status pages to install package and schedule autostart. git-svn-id: svn://svn.alpinelinux.org/acf/alpine-baselayout/trunk@1552 ab2d0c66-481e-0410-8bed-d214d4d58bed --- Makefile | 1 + alpine-baselayout.roles | 4 ++-- rc-controller.lua | 15 +++++++++++++ rc-edit-html.lsp | 11 +++++++++ rc-model.lua | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ rc-status-html.lsp | 40 +++++++++++++++++++++++++++++++++ 6 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 rc-controller.lua create mode 100644 rc-edit-html.lsp create mode 100644 rc-model.lua create mode 100644 rc-status-html.lsp diff --git a/Makefile b/Makefile index 2a38481..45c4372 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,7 @@ APP_DIST=\ logfiles* \ syslog* \ skins* \ + rc* \ EXTRA_DIST=README Makefile config.mk diff --git a/alpine-baselayout.roles b/alpine-baselayout.roles index adc0e41..24d0207 100644 --- a/alpine-baselayout.roles +++ b/alpine-baselayout.roles @@ -1,5 +1,5 @@ CREATE=interfaces:create,interfaces:editintfile -READ=health:storage,health:proc,health:network,health:modules,health:networkstats,interfaces:status,interfaces:read,logfiles:status,logfiles:view,logfiles:download,logfiles:tail,syslog:status,syslog:loginfo -UPDATE=interfaces:update,interfaces:ifup,interfaces:ifdown,skins:update,skins:read,syslog:startstop,syslog:config,syslog:expert +READ=health:storage,health:proc,health:network,health:modules,health:networkstats,interfaces:status,interfaces:read,logfiles:status,logfiles:view,logfiles:download,logfiles:tail,syslog:status,syslog:loginfo,rc:status +UPDATE=interfaces:update,interfaces:ifup,interfaces:ifdown,skins:update,skins:read,syslog:startstop,syslog:config,syslog:expert,rc:edit DELETE=interfaces:delete,logfiles:delete ALL=health:system,hostname:read diff --git a/rc-controller.lua b/rc-controller.lua new file mode 100644 index 0000000..3c00c41 --- /dev/null +++ b/rc-controller.lua @@ -0,0 +1,15 @@ +module (..., package.seeall) + +require("controllerfunctions") + +default_action = "status" + +status = function(self) + return self.model.status() +end + +edit = function(self) + return controllerfunctions.handle_form(self, + function() return self.model.read_sequence(self.clientdata.servicename) end, + self.model.update_sequence, self.clientdata, "Save", "Edit Startup Sequence") +end diff --git a/rc-edit-html.lsp b/rc-edit-html.lsp new file mode 100644 index 0000000..0c1896d --- /dev/null +++ b/rc-edit-html.lsp @@ -0,0 +1,11 @@ +<% local form, viewlibrary, page_info = ... +require("viewfunctions") +%> + +

<%= form.label %>

+<% + form.action = page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action + form.value.servicename.contenteditable = false + local order = {"servicename", "sequence", "kill", "system"} + displayform(form, order) +%> diff --git a/rc-model.lua b/rc-model.lua new file mode 100644 index 0000000..189d381 --- /dev/null +++ b/rc-model.lua @@ -0,0 +1,59 @@ +module (..., package.seeall) + +require("processinfo") +require("validator") + +local config + +status = function() + config = config or processinfo.read_startupsequence() + return cfe({ type="structure", value=config, label="Startup Sequence Status" }) +end + +read_sequence = function(servicename) + local value = {} + value.servicename = cfe({ value=servicename or "", label="Service Name" }) + value.sequence = cfe({ label="Startup Sequence" }) + value.kill = cfe({ type="boolean", value=false, label="Add kill link for shutdown" }) + value.system = cfe({ type="boolean", value=false, label="System init service" }) + + -- read in the value for the servicename + config = config or processinfo.read_startupsequence() + for i,conf in ipairs(config) do + if conf.servicename == servicename then + value.sequence.value = conf.sequence + value.kill.value = conf.kill + value.system.value = conf.system + break + end + end + + return cfe({ type="group", value=value, label="Service Startup Sequence"}) +end + + +update_sequence = function(sequence) + local success = false + sequence.value.servicename.errtxt = "Invalid service" + for name in posix.files("/etc/init.d") do + if name == sequence.value.servicename.value then + success = true + sequence.value.servicename.errtxt = nil + end + end + if sequence.value.sequence.value ~= "" and not validator.is_integer_in_range(sequence.value.sequence.value, 1, 99) then + success = false + sequence.value.sequence.errtxt = "Invalid sequence number" + end + if success then + if sequence.value.sequence.value == "" then + sequence.descr, sequence.errtxt = processinfo.delete_startupsequence(sequence.value.servicename.value) + else + sequence.descr, sequence.errtxt = processinfo.add_startupsequence(sequence.value.servicename.value, sequence.value.sequence.value, sequence.value.kill.value, sequence.value.system.value) + end + else + sequence.errtxt = "Failed to set sequence" + end + + return sequence +end diff --git a/rc-status-html.lsp b/rc-status-html.lsp new file mode 100644 index 0000000..1ea448a --- /dev/null +++ b/rc-status-html.lsp @@ -0,0 +1,40 @@ +<% local view, viewlibrary, page_info, session = ... %> +<% require("viewfunctions") %> + +<% if session.editresult then %> +

Command Result

+ <% if session.editresult.errtxt then io.write('

' .. string.gsub(session.editresult.errtxt, "\n", "
") .. "

\n") end + if session.editresult.descr then io.write('

' .. string.gsub(session.editresult.descr, "\n", "
") .. "

\n") end + for name,val in pairs(session.editresult.value) do + if val.errtxt then io.write('

' .. string.gsub(val.errtxt, "\n", "
") .. "

\n") end + end + session.editresult = nil +end %> + +

<%= view.label %>

+ + + +<% if session.permissions[page_info.controller].edit then %> + +<% end %> + +<% +for i,item in ipairs(view.value) do %> + + <% if session.permissions[page_info.controller].edit then + local result = viewlibrary.dispatch_component(page_info.controller.."/edit", {servicename=item.servicename}, true) + for name,val in pairs(result.value) do val.name=name end + if result.value.kill.value then result.value.kill.checked = "" end + if result.value.system.value then result.value.system.checked = "" end %> + " method="POST"> + + + + + <% else %> + + + <% end %> +<% end %> +
Service NameSequenceKill on shutdownSystem init serviceUpdate
<%= item.servicename %><%= html.form.hidden(result.value.servicename) %><%= html.form.text(result.value.sequence) %><%= html.form.checkbox(result.value.kill) %><%= html.form.checkbox(result.value.system) %>
<%= item.servicename %><%= item.sequence %><%= item.kill %><%= item.system %>
-- cgit v1.2.3