viernes, 1 de diciembre de 2017

Environment-modules

Environment-modules

Installation

It is possible that environment-modules is in your package manager. In debian based OS just look for the package
aptitude search environment modules
# or
# apt-cache search environment modules
It actually finds one package called environment-modules. You can install it in Debian based OS with
sudo aptitude install environment-modules
# or
# apt-get install environment-modules
After the installation, there is some automatic configuration to do
add.modules
It will ask to confirm the modifications (by default is yes)
/usr/bin/add.modules
    adds a few lines to the beginning of your
    /home/maikel/.cshrc, /home/maikel/.login,
    /home/maikel/.profile, /home/maikel/.bashrc, and
    possibly your /home/maikel/.kshenv (or whatever is
    specified by the ENV environment variable).
    The lines are prepended for sourcing the /etc/csh.modules or
    /etc/profile.modules files or to define the module alias or function.
    Why is it necessary?
    To insure that you will have access to modules for all subshells,
    these lines need to be added to some of your 'dot' files.

    Your old .cshrc, .login, .profile, .bashrc and .kshenv will be
    renamed to .login.old, .cshrc.old, .profile.old, .bashrc.old and
    .kshenv.old respectively.  So if you have any problems you will
    can easily restore them.

    This is version $Id: 196cf1d4fbd7d3deecf648e85ee37ead75a60a93 $ .

Continue on (type n for no - default=yes)?\c


Processing your .profile (your old one is .profile.old)
Cleaning .profile
Adding sourcing lines at beginning of .profile

Processing your .bashrc (your old one is .bashrc.old)
Cleaning .bashrc
Adding alias or function lines at beginning of .bashrc
You had no .kshenv as I see it.  Copying /etc/skel/.kshenv for you.
/bin/cp: cannot stat ‘/etc/skel/.kshenv’: No such file or directory
You had no .login as I see it.  Copying /etc/skel/.login for you.
/bin/cp: cannot stat ‘/etc/skel/.login’: No such file or directory
You had no .cshrc as I see it.  Copying /etc/skel/.cshrc for you.
/bin/cp: cannot stat ‘/etc/skel/.cshrc’: No such file or directory
Now, load the changes made into your .bashrc or own shell configuration file
source ~/.bashrc
Now, create and register the folder where all the modules will be specified
mkdir ~/modulefiles
module use ~/modulefiles
Test that it is working by calling
module avail
You should not see any error.

Creating your own modulefile

You can customize your own environment by creating and loading your own modulefiles. To use your own modulefiles you must first create a directory for them, register that directory and create the file. Here is a step by step example: Create and register the directory
mkdir ~/modulefiles
module use ~/modulefiles
This adds your newly created directory to the MODULEPATH environment variable and makes the files you place in there visible to the loader. Add the 'module use' directive to .profile or .bashrc depending on the file you use to initialize the module package. Create the modulefile Use this file as an example. The content is discussed below.
#%Module1.0####################################################################
##
##  mymodule modulefile
##
##  My new module that sets my personal environment
##
proc ModulesHelp { } {
        puts stderr "\tAdds my personal stuff to the environment."
}

## Create a whatis file.  Not nessecary but cool.
module-whatis   "Adds my own personal links, aliases and paths"

## Set a few personal aliases
set-alias       "ll"    "ls -al"

## Add my bin directory to the path
append-path     PATH    ~/bin

## Set an environment variable
setenv          MY_VAR  "hello"

Explanation

Line 1: This line contains the syntax version that is used. Line 2-6: Comments Line 7-9: This is optional. This prints a module specific help when used with the 'module help' command. Line 12: This command sets an alias. Line 15: This command appends ~/bin to your PATH environment variable. You can also use prepend-path Line 18: Create and set a new environment variable.

References

  • 2
  • http://modules.sourceforge.net/
  • http://www.admin-magazine.com/HPC/Articles/Environment-Modules
  • https://www.nersc.gov/users/software/nersc-user-environment/modules/