diff options
author | Mika Havela <mika.havela@gmail.com> | 2008-04-08 15:13:05 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2008-04-08 15:13:05 +0000 |
commit | dff2e5d4e7b7ef808d146ea64653701021a27ab2 (patch) | |
tree | 59cb11f9be55cef79359965ee3946433f48e6339 /openntpd-model.lua | |
parent | efe2a271ebf5894f581ddb151fb446e830782870 (diff) | |
download | acf-openntpd-dff2e5d4e7b7ef808d146ea64653701021a27ab2.tar.bz2 acf-openntpd-dff2e5d4e7b7ef808d146ea64653701021a27ab2.tar.xz |
Cleaning up code.
git-svn-id: svn://svn.alpinelinux.org/acf/openntpd/trunk@959 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'openntpd-model.lua')
-rw-r--r-- | openntpd-model.lua | 55 |
1 files changed, 22 insertions, 33 deletions
diff --git a/openntpd-model.lua b/openntpd-model.lua index d537629..f62c826 100644 --- a/openntpd-model.lua +++ b/openntpd-model.lua @@ -1,17 +1,18 @@ module (..., package.seeall) ---require("date") ---require("posix") +-- Load libraries require("format") require("fs") require("procps") require("getopts") require("daemoncontrol") +require("processinfo") +-- Set variables local configfile = "/etc/ntpd.conf" local confdfile = "/etc/conf.d/ntpd" -local processname = "openntpd" -local processname_short = "ntpd" +local packagename = "openntpd" +local processname = "ntpd" -- ################################################################################ -- LOCAL FUNCTIONS @@ -41,15 +42,6 @@ local function config_content( f ) return config end -local function get_version() - local cmd = "/sbin/apk_version -v -s " .. processname .. " | cut -d ' ' -f 1" - local cmd_output = io.popen( cmd ) - local cmd_output_result = cmd_output:read("*a") or "" - cmd_output:close() - return cmd_output_result -end - - local function last_time_change() local cmdoutput = {} local cmd, error = io.popen("cat /var/log/messages | grep ntpd | grep adjusting | tail -1" ,r) @@ -60,19 +52,6 @@ local function last_time_change() return cmdoutput1 .. cmdoutput2 end -local function autostarts() - local cmd_output_result - local cmd = "/sbin/rc_status | egrep '^S' | egrep '" .. processname_short .."' 2>/dev/null" - local f = io.popen( cmd ) - local cmdresult = f:read("*a") - if (cmdresult) and (#cmdresult > 0) then - cmd_output_result = "Process will autostart at next boot (at sequence '" .. string.match(cmdresult,"^%a+(%d%d)") .. "')" - else - cmd_output_error = "Not programmed to autostart" - end - f:close() - return cmd_output_result, cmd_output_error -end -- This function needs: -- addremove = [add|remove] @@ -182,6 +161,16 @@ local function addremove_config( addremove, variable, value ) errtxt="Something went wrong! You entered '" .. tostring(addremove) .. "' as function.", }) end + +local function process_status_text(procname) + local t = procps.pidof(procname) + if (t) and (#t > 0) then + return "Enabled" + else + return "Disabled" + end +end + -- ################################################################################ -- PUBLIC FUNCTIONS @@ -219,19 +208,19 @@ function getstatus () local file_result,err = fs.write_file(path, "") end - status.version = cfe({ - name = "version", + local value, errtxt = processinfo.package_version(packagename) + status.version = cfe({ name = "version", label="Program version", - value=get_version(), + value=value, + errtxt=errtxt, }) - status.status = cfe({ - name="status", + status.status = cfe({ name="status", label="Program status", - value=procps.pidof(processname_short), + value=process_status_text(processname), }) - local autostart_sequense, autostart_errtxt = autostarts() + local autostart_sequense, autostart_errtxt = processinfo.process_botsequence(processname) status.autostart = cfe({ name="autostart", label="Autostart sequence", value=autostart_sequense, |