Thursday, June 12, 2014

Linux-- Environment modules example

You can set your environment dynamically using environment modules.. Do not confused environment modules with the kernel modules. Environment modules are used for setting environment variables  via modulefiles. Popular shells are supported, including bash, ksh, zsh,sh, csh, tcsh, as well as scripting languages like perl and python.

In this post, I will create an environment module to set my environment according to my needs using module function. I will create a tcl file and use module load & unload functions to set & unset my environments using Linux modules.

Info:
module avail: to list all available modules you can load 
module list: to list your currently loaded modules 
module load moduleName: to load moduleName into your environment 
module unload moduleName: to unload moduleName from your environment
Modules are useful in managing different versions of applications. Modules can also be bundled into metamodules that will load an entire suite of different applications.

First, we create our module file in the modulespath as follows;
/usr/share/Modules/modulefiles/ermanv file:

#%Module1.0#####################################################################
##
## modules erman
##
## modulefiles/erman  Written by Erman Arslan
##
proc ModulesHelp { } {
        global version modroot

        puts stderr "this is erman test"
}

module-whatis   "Sets the environment for erman ERNAN=/home/applmgr/erman"

# for Tcl script use only
set     erman_home     /home/applmgr
set     version         4.6.2
set     sys             linux86

setenv         ERMAN              /home/applmgr/erman

Then we can execute module help to see if it s working.

[root@ermanprod modulefiles]# module help erman

----------- Module Specific Help for 'erman' ----------------------

this is erman test

We can see our modules description with whatis.

[root@ermanprod modulefiles]# module whatis erman
erman                : Sets the environment for erman ERNAN=/home/applmgr/erman

We see our module is detected by using module avail.

[root@ermanprod modulefiles]# module avail

------------------------------------------------------------------------------- /usr/share/Modules/modulefiles -------------------------------------------------------------------------------
dot         erman       module-cvs  module-info modules     null        use.own

-------------------------------------------------------------------------------------- /etc/modulefiles --------------------------------------------------------------------------------------
compat-openmpi-psm-x86_64 compat-openmpi-x86_64

Next, we load our module and all envrionment variables are set automatically.

[root@ermanprod modulefiles]# env |grep ERMAN
normally we dont have a environment variable called ERMAN

[root@ermanprod modulefiles]# module load erman
We load our module..
[root@ermanprod modulefiles]# env |grep ERMAN
Now we see our env variable ERMAN is set
ERMAN=/home/applmgr/erman

Now we unload our module and see we no longer have a variable called ERMAN.. Note that : we are in the same shell..
[root@erpprod modulefiles]# module unload erman
[root@erpprod modulefiles]# env |grep ERMAN

No comments :

Post a Comment

If you will ask a question, please don't comment here..

For your questions, please create an issue into my forum.

Forum Link: http://ermanarslan.blogspot.com.tr/p/forum.html

Register and create an issue in the related category.
I will support you from there.