Changeset 8558

Show
Ignore:
Timestamp:
04/15/12 16:30:54 (14 months ago)
Author:
jow
Message:

libs/sys: introduce luci.sys.init.start() and luci.sys.init.stop(), also execute all init action with an empty environment

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • luci/trunk/libs/sys/luasrc/sys.lua

    r8045 r8558  
    308308 
    309309    net.routes6(function(rt) 
    310         if rt.dest:prefix() == 0 and rt.device ~= "lo" and  
     310        if rt.dest:prefix() == 0 and rt.device ~= "lo" and 
    311311           (not route or route.metric > rt.metric) 
    312312        then 
     
    791791end 
    792792 
    793 --- Test whether the given init script is enabled 
    794 -- @param name  Name of the init script 
    795 -- @return      Boolean indicating whether init is enabled 
    796 function init.enabled(name) 
    797     if fs.access(init.dir..name) then 
    798         return ( call(init.dir..name.." enabled >/dev/null") == 0 ) 
    799     end 
    800     return false 
    801 end 
    802  
    803793--- Get the index of he given init script 
    804794-- @param name  Name of the init script 
     
    806796function init.index(name) 
    807797    if fs.access(init.dir..name) then 
    808         return call("source "..init.dir..name.." enabled >/dev/null; exit $START") 
    809     end 
     798        return call("env -i sh -c 'source %s%s; exit $START' >/dev/null" 
     799            %{ init.dir, name }) 
     800    end 
     801end 
     802 
     803local function init_action(action, name) 
     804    if fs.access(init.dir..name) then 
     805        return call("env -i %s%s %s >/dev/null" %{ init.dir, name, action }) 
     806    end 
     807end 
     808 
     809--- Test whether the given init script is enabled 
     810-- @param name  Name of the init script 
     811-- @return      Boolean indicating whether init is enabled 
     812function init.enabled(name) 
     813    return (init_action("enabled", name) == 0) 
    810814end 
    811815 
     
    814818-- @return      Boolean indicating success 
    815819function init.enable(name) 
    816     if fs.access(init.dir..name) then 
    817         return ( call(init.dir..name.." enable >/dev/null") == 1 ) 
    818     end 
     820    return (init_action("enable", name) == 1) 
    819821end 
    820822 
     
    823825-- @return      Boolean indicating success 
    824826function init.disable(name) 
    825     if fs.access(init.dir..name) then 
    826         return ( call(init.dir..name.." disable >/dev/null") == 0 ) 
    827     end 
     827    return (init_action("disable", name) == 0) 
     828end 
     829 
     830--- Start the given init script 
     831-- @param name  Name of the init script 
     832-- @return      Boolean indicating success 
     833function init.start(name) 
     834    return (init_action("start", name) == 0) 
     835end 
     836 
     837--- Stop the given init script 
     838-- @param name  Name of the init script 
     839-- @return      Boolean indicating success 
     840function init.stop(name) 
     841    return (init_action("stop", name) == 0) 
    828842end 
    829843