root/luci/branches/luci-0.10/modules/admin-core/luasrc/controller/admin/servicectl.lua @ 6749

Revision 6749, 1.4 KB (checked in by jow, 2 years ago)

luci-0.10: merge r6746, r6747 and r6748

  • Property svn:keywords set to Id
Line 
1--[[
2LuCI - Lua Configuration Interface
3
4Copyright 2010 Jo-Philipp Wich <xm@subsignal.org>
5
6Licensed under the Apache License, Version 2.0 (the "License");
7you may not use this file except in compliance with the License.
8You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11
12$Id$
13]]--
14
15module("luci.controller.admin.servicectl", package.seeall)
16
17function index()
18    luci.i18n.loadc("base")
19    local i18n = luci.i18n.translate
20
21    entry({"servicectl"}, alias("servicectl", "status"), nil, 1).sysauth = "root"
22    entry({"servicectl", "status"}, call("action_status"), nil, 2).leaf = true
23    entry({"servicectl", "restart"}, call("action_restart"), nil, 3).leaf = true
24end
25
26function action_status()
27    local data = nixio.fs.readfile("/var/run/luci-reload-status")
28    if data then
29        luci.http.write("/etc/config/")
30        luci.http.write(data)
31    else
32        luci.http.write("finish")
33    end
34end
35
36function action_restart()
37    if luci.dispatcher.context.requestpath[3] then
38        local service
39        local services = { }
40
41        for service in luci.dispatcher.context.requestpath[3]:gmatch("%w+") do
42            services[#services+1] = service
43        end
44
45        if nixio.fork() == 0 then
46            local i = nixio.open("/dev/null", "r")
47            local o = nixio.open("/dev/null", "w")
48
49            nixio.dup(i, nixio.stdin)
50            nixio.dup(o, nixio.stdout)
51
52            i:close()
53            o:close()
54
55            nixio.exec("/bin/sh", "/sbin/luci-reload", unpack(services))
56        else
57            luci.http.write("OK")
58            os.exit(0)
59        end
60    end
61end
Note: See TracBrowser for help on using the browser.