summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2008-09-25 19:12:54 +0000
committerTed Trask <ttrask01@yahoo.com>2008-09-25 19:12:54 +0000
commit493d9b8bf842a8b7e781f1672d4792fb84c79b16 (patch)
tree81de47905ba8404d3cb54fcdd398f3897624dfa8
parentd7dd7e74c68f715655c5c4e497b9f82ef336202e (diff)
downloadacf-core-493d9b8bf842a8b7e781f1672d4792fb84c79b16.tar.bz2
acf-core-493d9b8bf842a8b7e781f1672d4792fb84c79b16.tar.xz
Moved procps and daemoncontrol functionality into processinfo.lua and deleted procps.lua and daemoncontrol.lua. This saves space on the server.
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@1519 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--lib/Makefile2
-rw-r--r--lib/README22
-rw-r--r--lib/daemoncontrol.lua18
-rw-r--r--lib/modelfunctions.lua6
-rw-r--r--lib/processinfo.lua88
-rw-r--r--lib/procps.lua77
6 files changed, 103 insertions, 110 deletions
diff --git a/lib/Makefile b/lib/Makefile
index 409cf4e..5227c4b 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -5,12 +5,10 @@ LIB_DIST=fs.lua\
date.lua\
format.lua\
menubuilder.lua\
- procps.lua\
session.lua\
validator.lua\
authenticator.lua\
authenticator-plaintext.lua\
- daemoncontrol.lua\
getopts.lua\
roles.lua\
processinfo.lua\
diff --git a/lib/README b/lib/README
index 91b522b..d380934 100644
--- a/lib/README
+++ b/lib/README
@@ -4,15 +4,19 @@ Also we use Lua Posix for the rest of the functionality.
*** These are currently being worked on. ***
+apk.lua - Helps with package version/install/remove
+authenticator-plaintext.lua - sub-authenticator for plaintext files
+authenticator.lua - Used for authentication and roles, generic and uses sub-authenticator
+controllerfunctions.lua - Common controller functions
date.lua - Date and Time functions
-fs.lua - File and filesystem library
-pidof.lua - Process libraries not provided by LPOSIX
format.lua - Library to help reformat strings and tables.
-
-authenticator-plaintext.lua - Used to parse through the username:password file and for permission help
-validator.lua - Validate web input for ACF.
+fs.lua - File and filesystem library
+getopts.lua - Parsing certain type of config files
html.lua - Helps with form building in ACF.
-menubuilder.lua -Helps create the menus on left window in ACF
-privsep.lua - Helps with authorization with ACF
-session.lua -Helps with Session mangement in ACF
-
+menubuilder.lua - Helps create the menus on left window in ACF
+modelfunctions.lua - Common model functions
+processinfo.lua - Start/stop, find running, find version - process helpers
+roles.lua - Used to determine roles and permissions
+session.lua - Helps with Session mangement in ACF
+validator.lua - Validate web input for ACF.
+viewfunctions.lua - Common view functions
diff --git a/lib/daemoncontrol.lua b/lib/daemoncontrol.lua
deleted file mode 100644
index db9423c..0000000
--- a/lib/daemoncontrol.lua
+++ /dev/null
@@ -1,18 +0,0 @@
-module (..., package.seeall)
-require("posix")
-
-function daemoncontrol (process, action)
- local cmdmessage = ""
- if (string.lower(action) == "start") or (string.lower(action) == "stop") or (string.lower(action) == "restart") then
- local file = io.popen( "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin /etc/init.d/" ..
- process .. " " .. string.lower(action) .. " 2>&1" )
- if file ~= nil then
- cmdmessage = file:read( "*a" )
- file:close()
- end
- else
- return false,nil,"Unknown command!",action
- end
- posix.sleep(2) -- Wait for the process to start|stop
- return true,cmdmessage,nil,action
-end
diff --git a/lib/modelfunctions.lua b/lib/modelfunctions.lua
index 7b8e735..9dd1d6b 100644
--- a/lib/modelfunctions.lua
+++ b/lib/modelfunctions.lua
@@ -2,13 +2,11 @@ module(..., package.seeall)
-- Load libraries
require("fs")
-require("procps")
-require("daemoncontrol")
require("processinfo")
function getenabled(processname)
local result = cfe({ label = "Program status" })
- local t = procps.pidof(processname)
+ local t = processinfo.pidof(processname)
if (t) and (#t > 0) then
result.value = "Enabled"
else
@@ -19,7 +17,7 @@ end
function startstop_service(processname, action)
-- action is validated in daemoncontrol
- local cmdresult,cmdmessage,cmderror,cmdaction = daemoncontrol.daemoncontrol(processname, action)
+ local cmdresult,cmdmessage,cmderror,cmdaction = processinfo.daemoncontrol(processname, action)
return cfe({ value=cmdmessage or "", errtxt=cmderror, label="Start/Stop result" })
end
diff --git a/lib/processinfo.lua b/lib/processinfo.lua
index 2637b8c..dd15fa8 100644
--- a/lib/processinfo.lua
+++ b/lib/processinfo.lua
@@ -29,3 +29,91 @@ function process_botsequence(processname)
return cmdresult,cmderrors
end
+function daemoncontrol (process, action)
+ local cmdmessage = ""
+ if (string.lower(action) == "start") or (string.lower(action) == "stop") or (string.lower(action) == "restart") then
+ local file = io.popen( "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin /etc/init.d/" ..
+ process .. " " .. string.lower(action) .. " 2>&1" )
+ if file ~= nil then
+ cmdmessage = file:read( "*a" )
+ file:close()
+ end
+ else
+ return false,nil,"Unknown command!",action
+ end
+ posix.sleep(2) -- Wait for the process to start|stop
+ return true,cmdmessage,nil,action
+end
+
+-- the following methods are available:
+-- /proc/<pid>/stat the comm field (2nd) field contains name but only up
+-- to 15 chars. does not resolve links
+--
+-- /proc/<pid>/cmdline argv[0] contains the command. However if it is a script
+-- then will the interpreter show up
+--
+-- /proc/<pid>/exe link to exe file. this will resolv links
+--
+-- returns list of all pids for given exe name
+
+--[[
+-- gives lots of false positives for busybox
+local function is_exe(path, name)
+ local f = posix.readlink(path.."/exe")
+ if f and (f == name or posix.basename(f) == name) then
+ return true
+ else
+ return false
+ end
+end
+]]--
+
+
+local function is_stat(path, name)
+ local f = io.open(path.."/stat")
+ if (f) then
+ local line = f:read()
+ local p = string.gsub(line, ".*%(", "")
+ p = string.gsub(p, "%).*", "")
+ f:close()
+ end
+ if p ~= nil then
+ if string.len(name) <= 15 and p == name then
+ return true
+ end
+ end
+ return false
+end
+
+local function is_cmdline(path, name)
+ local f = io.open(path.."/cmdline")
+ if f == nil then
+ return false
+ end
+ local line = f:read()
+ f:close()
+ if line == nil then
+ return false
+ end
+ local arg0 = string.gsub(line, string.char(0)..".*", "")
+ if posix.basename(arg0) == name then
+ return true
+ end
+end
+
+function pidof(name)
+ local pids = {}
+ local i, j
+
+ for i,j in pairs(posix.glob("/proc/[0-9]*")) do
+ local pid = tonumber(posix.basename(j))
+ if is_stat(j, name) or is_cmdline(j, name) then
+ table.insert(pids, pid)
+ end
+ end
+ if #pids == 0 then
+ pids = nil
+ end
+ return pids
+end
+
diff --git a/lib/procps.lua b/lib/procps.lua
deleted file mode 100644
index 057f2e2..0000000
--- a/lib/procps.lua
+++ /dev/null
@@ -1,77 +0,0 @@
-
-module(..., package.seeall)
-
-require("posix")
-
--- the following methods are available:
--- /proc/<pid>/stat the comm field (2nd) field contains name but only up
--- to 15 chars. does not resolve links
---
--- /proc/<pid>/cmdline argv[0] contains the command. However if it is a script
--- then will the interpreter show up
---
--- /proc/<pid>/exe link to exe file. this will resolv links
---
--- returns list of all pids for given exe name
-
---[[
--- gives lots of false positives for busybox
-local function is_exe(path, name)
- local f = posix.readlink(path.."/exe")
- if f and (f == name or posix.basename(f) == name) then
- return true
- else
- return false
- end
-end
-]]--
-
-
-local function is_stat(path, name)
- local f = io.open(path.."/stat")
- if (f) then
- local line = f:read()
- local p = string.gsub(line, ".*%(", "")
- p = string.gsub(p, "%).*", "")
- f:close()
- end
- if p ~= nil then
- if string.len(name) <= 15 and p == name then
- return true
- end
- end
- return false
-end
-
-local function is_cmdline(path, name)
- local f = io.open(path.."/cmdline")
- if f == nil then
- return false
- end
- local line = f:read()
- f:close()
- if line == nil then
- return false
- end
- local arg0 = string.gsub(line, string.char(0)..".*", "")
- if posix.basename(arg0) == name then
- return true
- end
-end
-
-function pidof(name)
- local pids = {}
- local i, j
-
- for i,j in pairs(posix.glob("/proc/[0-9]*")) do
- local pid = tonumber(posix.basename(j))
- if is_stat(j, name) or is_cmdline(j, name) then
- table.insert(pids, pid)
- end
- end
- if #pids == 0 then
- pids = nil
- end
- return pids
-end
-