why run module unload failed in modulefile? - module

I am a newbie.
I found an interesting thing about Environment modules.
please see the following process.
my linux OS is redhat5.8.
I have installed environment modules 3.2.10, tcl8.6.6,
source init/csh successfully.
I write a qq/{61_0, 61_1, 61_2} modulefile respectively.
take qq/61_0 as an example.
cat 61_0:
\#%Module1.0
set curNameVersion [module-info name]
set curName [lindex [split $curNameVersion "/"] 0]
set var_name "61_PAT"
set install_path /soft/qq/61_0
if { [module-info mode load] } {
puts stderr "loaded $curNameVersion"
if { [info exists env($var_name)] } {
if { $env($var_name) != $install_path } {
puts stderr "rm loaded $curName"
module unload $curName
}
}
}
setenv $var_name $install_path
puts stderr "done 61_0"
.
.
61_1 modulefile is basically similar to 61_0 except set install_path /soft/qq/61_1 and puts stderr "done 61_1"
61_2 modulefile is basically similar to 61_0 except set install_path /soft/qq/61_2 and puts stderr "done 61_2"
3.
^Linux^: module add qq/61_0
loaded qq/61_0
done 61_0
^Linux^: module add qq/61_1
loaded qq/61_1
rm loaded qq
loaded qq/61_0
done 61_0
done 61_1
^Linux^: module add qq/61_2
done 61_0
done 61_0
done 61_0
..
...
done 61_0
done 61_0
done 61_2
4.
^Linux^: module list
Currently Loaded Modulefiles:
1) qq/61_0 2) qq/61_1 3) qq/61_2
^Linux^: echo $_LMFILES_
/software/qq/61_0:/software/qq/61_1:/software/qq/61_2
^Linux^: echo $LOADEDMODULES
qq/61_0:qq/61_1:qq/61_2
my question is:
it should not load multi-version for the same tool qq,
when load another version, it should module rm other firstly.
although I have module unload in modulefile, but it looks like module unload $curName sentence not work
when run 'module add qq/61_1', it means that, it will rm loaded qq/61_0 firstly,
and then execute qq/61_0 modulefile,
because it is unload for qq/61_0, it should not output line 'loaded qq/61_0'.
but it output 'loaded qq/61_0'.
why?
why is there so many many output 'done 61_0' when run 'module add qq/61_2'?
echo $LMFILES and echo $LOADEDMODULES have proven that it exists multi-version for the same tool,
how to keep only load one version?
anybody can help me?
Thanks in advance

The issue you describe is coming from a bug affecting Modules version <= 3.2.10. Newer Modules version (> 3.2.10) or up-to-date "environment-modules" package on RedHat-like Linux distribution have fixed this issue:
With a fixed Modules version, the process you describe seems correct (tested on Modules 3.2.10 and greater on a Fedora system):
$ module add qq/61_0
loaded qq/61_0
done 61_0
$ module add qq/61_1
loaded qq/61_1
rm loaded qq
done 61_0
done 61_1
$ module list
Currently Loaded Modulefiles:
1) qq/61_1
$ module add qq/61_2
loaded qq/61_2
rm loaded qq
done 61_1
done 61_2
$ module list
Currently Loaded Modulefiles:
1) qq/61_2

Related

How to dynamically pass parameter to the RPM during installation

We are in need to dynamically pass a variable during RPM installation and capture it in the spec file to trigger a script in %post
Following is the command
RPM Install Command
sudo rpm -Uvh --force abc.noarch.rpm --define '_ip 10.1.2.4' --define 'version 3'
**abc.spec**
Name: abc
Version: 1
Release: 1.0
Summary: Test
%{!?_ip: %define _ip 0.0.0.0 }
%{!?_version: %define _version 0 }
%post
echo "ip:::: %{_ip}"
echo "VESION:::: %{_version}"
So when I run the RPM with the above command , I get the following output.
[root#test solution]$ sudo rpm -Uvh --force abc.noarch.rpm --define '_ip 10.1.2.4' --define 'version 3'
Preparing... ################################# [100%]
Updating / installing...
1:abc ################################# [ 50%]
ip:::: 0.0.0.0
VESION:::: 0
Though i pass a different value in the CLI command , I still see that the argument which I pass is not been captured in the spec file.
Need inputs on how to capture the values which im passing the CLI .
The option --define defines macro. Macros are evaluated when building an RPM from SRC.RPM using rpmbuild. The binary (does not matter if arch or noarch) package has every macro already expanded. Even the %bindir etc.
The RPM ecosystem was designed as non-interactive. This is a big difference from the DEB ecosystem when questions can be raised using debconf.
You cannot workaround it. You cannot ask even by directly reading STDIN as rpm close this descriptor before executing scriptlets.
The best practice is to use configuration files. E.g. /etc/abc/ip.conf. And:
either instruct user to manualy (or using Ansible) alter that file and store their correct data
or do NOT distribute /etc/abc/ip.conf in main abc package and instead require abc-config. And then create one or more config packages which will be like:
Package: abc-testing-config
Provides: abc-config
...
%files
/etc/abc/ip.conf
And you then instruct users to install abc abc-test-config. Or it can be abc abc-EMEA-config etc....

Read host system's environment variables build time in Singularity

When I'm building a Singularity container I'd like to read environment variables from the host system in the %post section. I've been looking online for a way to achieve this, but to no avail. I'm starting to question if this is even possible at the moment, but I can't find any mentions of it being possible/impossible.
Example:
Singularity definition file: recipe
BootStrap: docker
From: continuumio/anaconda3
%runscript
%post
echo $TEST_ENV_VARIABLE
On the host system / OS
export TEST_ENV_VARIABLE='foo'
sudo singularity build test.sif recipe
prints only a blank line when echoing TEST_ENV_VARIABLE.
If there is no way of reading host system's environment variables in the %post section, are there any other ways of passing arguments into the recipe that could be used build-time?
That is not currently possible, though there is an open issue for that functionality. I'm not personally a fan of dynamic build options as it makes it harder to guarantee reproducibility.
If you do want something more dynamic, you could use a template to create different definition files. A very simplistic example:
$ cat gen_def.py
#!/usr/bin/env python3
import sys
my_def = """BootStrap: docker
From: continuumio/anaconda3
%post
echo This is {0}
echo This is {1}"""
print(my_def.format(*sys.argv[1:]))
$ ./gen_def.py one two > Singularity.custom
$ sudo singularity build test.sif Singularity.custom

Set up PATH correctly for zsh and RVM

I just switched to ZSH and are having issues with RVM. I believe it is related to my PATH. One issue that I have is when I start a new tab in iTerm2, the ruby version switches to 1.9.3 even though the default is 2.0.0. Here is my .zshrc file.
export PATH="/Users/okyretina/.rvm/gems/ruby-2.0.0-p353#iou-web/bin:$PATH:$HOME/.rvm/bin:/Users/okyretina/.rvm/gems/ruby-1.9.3-p429#rails-3.2.13/bin:/Users/okyretina/.rvm/gems/ruby-1.9.3-p429#global/bin:/Users/okyretina/.rvm/rubies/ruby-1.9.3-p429/bin:/Users/okyretina/.rvm/bin:/Users/okyretina/bin:/Users/okyretina/xbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/okyretina/phantomjs/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/share/npm/bin"
# load RVM
# insure /usr/local/bin comes before /usr/bin
# PATH="/usr/local/bin:/usr/local/sbin:$PATH"
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
# This command should be at the end for it loads the oh-my-zsh.sh script
source $ZSH/oh-my-zsh.sh
my export PATH is very long but I'm not sure which one is no longer needed.
run:
rvm get stable --auto-dotfiles
it will reorganize your shell initialization files to load rvm in proper places, make sure to read all the output - it does print information and warnings that are important.
Probably my answer won't help you to solve your particular problem but I will try to help you in finding a solution.
Your $PATH is pretty long and it's hard to make sure that the files have a correct order. In zsh you can set $PATH like this (example taken from my config):
typeset -U path
path=(
/usr/local/{bin,sbin}
/usr/local/git/bin
/usr/local/opt/coreutils/libexec/gnubin
$path
)
As you can see this method much better in terms of readability and it can help you to make sure that the order in $PATH is correct.
Also in your paths you use both "/Users/okyretina/" and $HOME. I think it makes sense to use $HOME in all cases so your paths will look much shorter and it will be easier to read them.

Installing rvm on Linux Mint KDE

I'm having a hard time getting rvm to install on Mint. I tried the instructions at:
https://rvm.beginrescueend.com/rvm/install/
The first step proceeds without incident. However, when I try to run source ~/.bash_profile, I get an error message stating that no such directory exists. I can restart the terminal, but it still says that "The program 'rvm' is currently not installed...."
A .rvm directory in now present in my home directory and the binary is there. I'm suspecting that this means that I need to add something in my .bashrc (or somewhere else) to tell the OS where to look for executables. But I'm still a little new at Linux and am uncertain where exactly it needs to go or what it should be.
The Answer in the same site:
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
it works for me.
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function
Looks like this needs to be tacked onto the end of the .bashrc file if it isn't present.

Updating files after RVM install

I have installed RVM enroute to updating and running different ruby and rails. After install I received message to update shell's loading files.
1) Place the folowing line at the end of your shell's loading files
(.bashrc or .bash_profile for bash and .zshrc for zsh),
after all PATH/variable settings:
[[ -s "/Users/eric/.rvm/scripts/rvm" ]] && source "/Users/eric/.rvm/scripts/rvm" # This loads RVM into a shell session.
You only need to add this line the first time you install rvm.
I typed [[ -s "/Users/eric/.rvm/scripts/rvm" ]] && source "/Users/eric/.rvm/scripts/rvm"
and hit enter. Does this update my files? Or do I have to open some type of file and cut and paste code?
Since I did not see any notice as stated below from part 2 of the post install, I closed the shell and opened a new one. but the RVM command does not seem to work. Part 2 of the instructions post install was:
2) Ensure that there is no 'return' from inside the ~/.bashrc file,
otherwise rvm may be prevented from working properly.
This means that if you see something like:
'[ -z "$PS1" ] && return'
then you change this line to:
if [[ -n "$PS1" ]] ; then
# ... original content that was below the '&& return' line ...
fi # <= be sure to close the if at the end of the .bashrc.
# This is a good place to source rvm v v v
[[ -s "/Users/eric/.rvm/scripts/rvm" ]] && source "/Users/eric/.rvm/scripts/rvm" # This loads RVM into a shell session.
EOF - This marks the end of the .bashrc file
Be absolutely *sure* to REMOVE the '&& return'.
If you wish to DRY up your config you can 'source ~/.bashrc' at the bottom of your .bash_profile.
Placing all non-interactive (non login) items in the .bashrc,
including the 'source' line above and any environment settings.
Thanks for the help as I am very new and trying to learn RoR but so far have not been able to get past the setup in many of the tutorials I've attempted. It seems many [
1 2 are out of date with new software or I get error messages before I can even attempt to learn the code. If someone knows of a good beginner tutorial that would be great. Thanks again!
The snippet that the installer gives you need to go in a file called the bashrc. The file lives in your home directory: /Users/eric/.bashrc
You need to edit this file and add the line from rvm and then you should be good to go.
As for getting rolling with rails I'd recommend The Pragmatic Programmers book on rails. You can find their books at pragprog.com
If you're on Ubuntu, my tutorial on setting rvm will get you roll all the way up to rails installation:
http://blog.dcxn.com/2011/06/20/setting-up-rvm-on-ubuntu-11-04/