From 6d638ac9d28eac2c144d229359b64c0edaee2b4d Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Mon, 16 Jan 2012 22:01:42 +0000 Subject: Modified rc to add service status and startstop actions --- alpine-baselayout.roles | 4 ++-- rc-controller.lua | 4 ++++ rc-model.lua | 28 +++++++++++++++++++++++++++- rc-status-html.lsp | 19 +++++++++++++++---- 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/alpine-baselayout.roles b/alpine-baselayout.roles index 257d8d8..c17fa71 100644 --- a/alpine-baselayout.roles +++ b/alpine-baselayout.roles @@ -1,5 +1,5 @@ GUEST=hostname:read -USER=cron:status,cron:startstop,health:system,health:storage,health:proc,health:network,health:networkstats,interfaces:status,interfaces:read,interfaces:restart,logfiles:status,logfiles:view,logfiles:download,logfiles:tail,modules:status,syslog:status,syslog:loginfo,syslog:startstop,rc:status +USER=cron:status,cron:startstop,health:system,health:storage,health:proc,health:network,health:networkstats,interfaces:status,interfaces:read,interfaces:restart,logfiles:status,logfiles:view,logfiles:download,logfiles:tail,modules:status,syslog:status,syslog:loginfo,syslog:startstop,rc:status,rc:startstop EDITOR=cron:listjobs,hostname:edit,interfaces:delete,interfaces:create,interfaces:update,interfaces:ifup,interfaces:ifdown,logfiles:delete,syslog:config,rc:edit EXPERT=cron:editjob,cron:deletejob,cron:movejob,cron:createjob,cron:expert,syslog:expert,interfaces:editintfile,modules:edit,modules:reload -ADMIN=cron:status,cron:startstop,cron:listjobs,cron:editjob,cron:deletejob,cron:movejob,cron:createjob,cron:expert,hostname:read,health:system,health:storage,health:proc,health:network,health:networkstats,interfaces:status,interfaces:read,interfaces:restart,logfiles:status,logfiles:view,logfiles:download,logfiles:tail,modules:status,syslog:status,syslog:loginfo,syslog:startstop,rc:status,hostname:edit,interfaces:delete,interfaces:create,interfaces:update,interfaces:ifup,interfaces:ifdown,logfiles:delete,syslog:config,rc:edit,syslog:expert,interfaces:editintfile,modules:edit,modules:reload,password:edit +ADMIN=cron:status,cron:startstop,cron:listjobs,cron:editjob,cron:deletejob,cron:movejob,cron:createjob,cron:expert,hostname:read,health:system,health:storage,health:proc,health:network,health:networkstats,interfaces:status,interfaces:read,interfaces:restart,logfiles:status,logfiles:view,logfiles:download,logfiles:tail,modules:status,syslog:status,syslog:loginfo,syslog:startstop,rc:status,rc:startstop,hostname:edit,interfaces:delete,interfaces:create,interfaces:update,interfaces:ifup,interfaces:ifdown,logfiles:delete,syslog:config,rc:edit,syslog:expert,interfaces:editintfile,modules:edit,modules:reload,password:edit diff --git a/rc-controller.lua b/rc-controller.lua index 69fd183..ba235b6 100644 --- a/rc-controller.lua +++ b/rc-controller.lua @@ -13,3 +13,7 @@ edit = function(self) function() return self.model.read_runlevels(self.clientdata.servicename) end, self.model.update_runlevels, self.clientdata, "Save", "Edit Service Runlevels") end + +startstop = function(self) + return self:redirect_to_referrer(self.model.handle_startstop(self.clientdata.servicename, self.clientdata.action)) +end diff --git a/rc-model.lua b/rc-model.lua index c213e1f..215d02d 100644 --- a/rc-model.lua +++ b/rc-model.lua @@ -17,7 +17,16 @@ table.sort(runlevels) local config status = function() - config = config or processinfo.read_initrunlevels() + if not config then + config = processinfo.read_initrunlevels() + for i,c in pairs(config) do + c.actions, c.description = processinfo.daemon_actions(c.servicename) + c.status = processinfo.daemoncontrol(c.servicename, "status") + if c.status then + c.status = string.match(c.status, "status: (.*)") + end + end + end return cfe({ type="structure", value=config, label="Init Runlevels" }) end @@ -73,3 +82,20 @@ update_runlevels = function(service) return service end + +handle_startstop = function(servicename, action) + local result = "" + local errtxt + local actions,errtxt = processinfo.daemon_actions(servicename) + if actions then + errtxt = nil + local reverseactions = {} + for i,act in ipairs(actions) do reverseactions[string.lower(act)] = i end + if reverseactions[string.lower(action)] then + result, errtxt = processinfo.daemoncontrol(servicename, action) + else + errtxt = "Unknown command!" + end + end + return cfe({ label="Start/Stop result", value=result, errtxt=errtxt }) +end diff --git a/rc-status-html.lsp b/rc-status-html.lsp index 446c826..b04913a 100644 --- a/rc-status-html.lsp +++ b/rc-status-html.lsp @@ -1,16 +1,19 @@ <% local view, viewlibrary, page_info, session = ... %> <% require("viewfunctions") %> -<% displaycommandresults({"edit"}, session) %> +<% displaycommandresults({"edit", "startstop"}, session) %>

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

<% if viewlibrary.check_permission("edit") then %> - + <% end %> - + + + + <% for i,item in ipairs(view.value) do %> @@ -18,7 +21,15 @@ for i,item in ipairs(view.value) do %> <% if viewlibrary.check_permission("edit") then %> + <% if viewlibrary.check_permission("startstop") and item.actions then + for i,a in ipairs(item.actions) do + print(html.link{value="startstop?servicename="..item.servicename.."&action="..a, label=a:gsub("^%l", string.upper).." " }) + end + end %> + + + + <% end %>
ActionActionService NameRunlevelsService NameStatusRunlevelsDescription
<%= html.link{value="edit?servicename="..item.servicename.."&redir="..page_info.orig_action, label="Edit " } %> <% end %> - <%= html.html_escape(item.servicename) %><%= html.html_escape(table.concat(item.runlevels, ", ")) %> <%= html.html_escape(item.servicename) %><%= html.html_escape(item.status) %><%= html.html_escape(table.concat(item.runlevels, ", ")) %> <%= html.html_escape(item.description) %>
-- cgit v1.2.3