summaryrefslogtreecommitdiffstats
path: root/lib/processinfo.lua
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2008-10-11 12:57:42 +0000
committerTed Trask <ttrask01@yahoo.com>2008-10-11 12:57:42 +0000
commit040350eced7897f52402c466d14378ca62cf00b1 (patch)
tree5e62bfed641d1ee9551a114b869cd419019a6796 /lib/processinfo.lua
parent5ff7837be35aab168c05a6efc0e5945e2f664b63 (diff)
downloadacf-core-040350eced7897f52402c466d14378ca62cf00b1.tar.bz2
acf-core-040350eced7897f52402c466d14378ca62cf00b1.tar.xz
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/core/trunk@1552 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'lib/processinfo.lua')
-rw-r--r--lib/processinfo.lua81
1 files changed, 78 insertions, 3 deletions
diff --git a/lib/processinfo.lua b/lib/processinfo.lua
index e1eca4e..33ece60 100644
--- a/lib/processinfo.lua
+++ b/lib/processinfo.lua
@@ -3,6 +3,8 @@ module(..., package.seeall)
require("posix")
+local path = "PATH=/usr/bin:/bin:/usr/sbin:/sbin "
+
function package_version(packagename)
local cmderrors
local f = io.popen( "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin apk_version -vs " .. packagename .." | egrep -v 'acf' 2>/dev/null" )
@@ -16,12 +18,12 @@ function package_version(packagename)
return cmdresult,cmderrors
end
-function process_botsequence(processname)
+function process_startupsequence(servicename)
local cmderrors
- local f = io.popen( "/sbin/rc_status | egrep '^S' | egrep '" .. processname .."' 2>/dev/null" )
+ local f = io.popen( "/sbin/rc_status | egrep '^S' | egrep '" .. servicename .."' 2>/dev/null" )
local cmdresult = f:read("*a")
if (cmdresult) and (#cmdresult > 0) then
- cmdresult = "Process will autostart at next boot (at sequence '" .. string.match(cmdresult,"^%a+(%d%d)") .. "')"
+ cmdresult = "Service will autostart at next boot (at sequence '" .. string.match(cmdresult,"^%a+(%d%d)") .. "')"
else
cmderrors = "Not programmed to autostart"
end
@@ -29,6 +31,79 @@ function process_botsequence(processname)
return cmdresult,cmderrors
end
+function read_startupsequence()
+ local config = {}
+ local f = io.popen( "/sbin/rc_status 2>/dev/null" )
+ local cmdresult = f:read("*a") or ""
+ f:close()
+ local section = 0
+ for line in string.gmatch(cmdresult, "([^\n]*)\n?") do
+ local sequence, service = string.match(line, "(%d%d)(%S+)")
+ if service then
+ if section == 3 then -- kill section
+ for i,cfg in ipairs(config) do
+ if cfg.servicename == service then
+ cfg.kill = true
+ break
+ end
+ end
+ else
+ config[#config+1] = {servicename=service, sequence=sequence, kill=false, system=(section == 1)}
+ end
+ elseif string.match(line, "^rc.%.d:") then
+ section = section + 1
+ end
+ end
+ -- Add in any missing init.d scripts
+ local reverseservices = {} for i,cfg in ipairs(config) do reverseservices[cfg.servicename] = i end
+ local temp = {}
+ for name in posix.files("/etc/init.d") do
+ if not reverseservices[name] and not string.find(name, "^rc[KLS]$") and not string.find(name, "^..?$") then
+ temp[#temp+1] = {servicename=name, sequence="", kill=false, system=false}
+ end
+ end
+ table.sort(temp, function(a,b) return a.servicename < b.servicename end)
+ for i,val in ipairs(temp) do
+ config[#config+1] = val
+ end
+ return config
+end
+
+function add_startupsequence(servicename, sequence, kill, system)
+ local cmdresult,cmderrors
+ if not servicename then
+ cmderrors = "Invalid service name"
+ else
+ local cmd = {path, "rc_add"}
+ if kill then cmd[#cmd+1] = "-k" end
+ if system then cmd[#cmd+1] = "-S" end
+ if sequence then cmd[#cmd+1] = "-s "..sequence end
+ cmd[#cmd+1] = servicename
+ cmd[#cmd+1] = "2>&1"
+ delete_startupsequence(servicename)
+ local f = io.popen(table.concat(cmd, " "))
+ cmdresult = f:read("*a")
+ f:close()
+ if cmdresult == "" then cmdresult = "Added sequence" end
+ end
+
+ return cmdresult,cmderrors
+end
+
+function delete_startupsequence(servicename)
+ local cmdresult,cmderrors
+ if not servicename then
+ cmderrors = "Invalid service name"
+ else
+ local f = io.popen(path.."rc_delete "..servicename)
+ cmdresult = f:read("*a")
+ f:close()
+ if cmdresult == "" then cmderrors = "Failed to delete sequence" end
+ end
+
+ return cmdresult,cmderrors
+end
+
function daemoncontrol (process, action)
local cmdresult = ""
local cmderrors