summaryrefslogtreecommitdiffstats
path: root/lib/daemoncontrol.lua
blob: 838b03960ad1aeaa6a80d755b54558055533c73e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module (..., package.seeall)
require("posix")

function daemoncontrol (process, action)
	local cmdresult = ""
	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 .. " " .. action .. " 2>&1" )
		if file ~= nil then
			line = file:read( "*l" )
			while line ~= nil do
				cmdresult = cmdresult .. "\n" .. line
				line = file:read( "*l" )
			end
			file:close()
		end
	else
		cmdresult = "Unknown command!"
	end
	posix.sleep(2)	-- Wait for the process to start|stop
	return {cmdresult=cmdresult, process=process, action=action,cmderror=cmderror }
end