Re: [Lmod-users] adding hooks to modules
A Lua based environment module system that reads TCL modulefiles.
Brought to you by:
rtmclay
|
From: Robert M. <mc...@ta...> - 2013-09-02 20:11:09
|
I have added support for TCL modulefiles to use the system command. This change has been pushed to the github repo( github.com/TACC/lmod) if you would like to try it. Please let me know if it works for you. R. On Thu, Aug 29, 2013 at 8:41 PM, Robert McLay <mc...@ta...> wrote: > About your question about system function for TCL modules. It is true > that is not supported by the current version of lmod. You can use the > "execute" function inside of a lua modulefile. I think that it is possible > tcl modulefile could translate the "system" TCL function to use the > "execute" function but I'll have to think about how. > > Lmod already has support for tracking module usage. All you need do is > define the load_hook function in your "SitePackage.lua" file. If you set > "LMOD_PACKAGE_PATH" to point to the directory that contains your > "SitePackage.lua" file you can use the load_hook function. Below is an > example SitePackage.lua that uses the "logger" command to write to the > syslog daemon. > > *Important node: If you put this function in SitePackage.lua ( and > modify it to suit your needs). You DO NOT need to change a single line in > any modulefile. This will work with both lua and TCL modulefiles.* > > require("strict") > require("string_split") > local hook = require("Hook") > local getenv = os.getenv > local concatTbl = table.concat > > local function load_hook(t) > -- t is a table containing: > -- t.modFullName: Full name of the Module, > -- t.fn: the path of the modulefile. > > local lmod_logger_list = getenv("LMOD_LOGGER_LIST") > > -- Suppose that LMOD_LOGGER_LIST contained Key name , Env Name > -- For example: > -- LMOD_LOGGER_LIST: "U,USER:H,HOSTNAME:ID,PBS_JOBID" > > local a = {} > > a[#a+1] = "M" .. t.modFullName > a[#a+1] = "FN" .. t.fn > > for keyName in split(":") do > local _, _, key, name = keyName:find("(.*),(.*)") > local value = getenv(name) > if (value) then > a[#a+1] = key .. value > end > end > local s = concatTbl(a," ") --> "M${module} FN${fn} U${user} > H${hostname} ID${pbs_id}" > > local cmd = "logger -t lmod -p local0.info " .. s > os.execute(cmd) > end > > hook.register("load", load_hook) > > ------------------------------- > > In the above code (in SitePackage.lua), You have set the environment > variable LMOD_LOGGER_LIST to be > > U,USER:H,HOSTNAME:ID,PBS_JOBID > > So the format is Key name (U) COMMA , environment variable name (USER). > This code reads the environment variable and parses it. If the > environment variable has a value then it gets added to the logger output. > This way if you have use the same trick to record interactive and batch > jobs, PBS_JOBID won't have a value when interactive. This will load > hook will be called on every module that gets loaded. You get the module > name and modulefile for "free". > > > > On Thu, Aug 29, 2013 at 2:19 PM, Jiří Machala <ma...@ma...>wrote: > >> Hello everybody, >> I've been trying lmod some more and I'd like to add some hooks to log >> which >> modules use our users most and maybe for checking some user permissions >> etc >> (when I think about it now, adding some variables for architecture etc, >> would >> also be nice). >> >> My idea is we would add to lmod some script and whenever "module load" was >> called, this script would be called and the name of module would be >> passed to >> it. >> >> What do you think would be the best way to do it? Or do you think there is >> some completly other better way to achive the same goal? >> >> On unrelated note: >> in a couple of our TCL modules we use command "system" and it seems to be >> unimplemented, I suppose it would be easiest to just rewrite it to lua, >> wouldn't it? >> >> Jiri Machala, >> tech support at MetaCentrum VO(metavo.metacentrum.cz) >> >> >> P.S.: >> sorry for possible duplicate message, I sent it first from the wrong mail >> address >> >> >> ------------------------------------------------------------------------------ >> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! >> Discover the easy way to master current and previous Microsoft >> technologies >> and advance your career. Get an incredible 1,500+ hours of step-by-step >> tutorial videos with LearnDevNow. Subscribe today and save! >> >> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk >> _______________________________________________ >> Lmod-users mailing list >> Lmo...@li... >> https://lists.sourceforge.net/lists/listinfo/lmod-users >> > > > > -- > Robert McLay, Ph.D. > TACC > Manager, HPC Software Tools > (512) 232-8104 > > -- Robert McLay, Ph.D. TACC Manager, HPC Software Tools (512) 232-8104 |