Blame Automation/Manuals/Understanding_Modules/understanding_modules.asciidoc

Alain Reguera Delgado 393983
Understanding Modules
Alain Reguera Delgado 393983
=====================
Alain Reguera Delgado 393983
Alain Reguera Delgado <al@centos.org.cu>
Alain Reguera Delgado a76055
v0.1, Oct 2013
Alain Reguera Delgado 393983
Alain Reguera Delgado a76055
Overview
Alain Reguera Delgado a76055
--------
Alain Reguera Delgado 393983
Alain Reguera Delgado a76055
From version 0.5, the *centos-art.sh* script introduces the idea of
Alain Reguera Delgado a76055
modules to its base design. Modules are a collection of functions
Alain Reguera Delgado a76055
written in Bash that can call one another to create individual
Alain Reguera Delgado a76055
execution environments. They may be nested to achieve high levels of
Alain Reguera Delgado 393983
maintainability and extensibility. This make possible for modules
Alain Reguera Delgado 393983
writers to divide complicated tasks into smaller tasks that can be
Alain Reguera Delgado 393983
easier to debug, maintain and share with other modules efficiently
Alain Reguera Delgado 393983
(e.g., instead of loading modules all at once, they are only loaded at
Alain Reguera Delgado 393983
demand and unset once they conclude their execution).
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
This article describes the modular design of *centos-art.sh* script.
Alain Reguera Delgado a76055
It is a good place for you to start if you are planning to contribute
Alain Reguera Delgado a76055
new module environments to *centos-art.sh* script or want to know more
Alain Reguera Delgado a76055
about how it works. The next section delves into what a module
Alain Reguera Delgado a76055
environment is, the three module types you can find in it and the
Alain Reguera Delgado a76055
correct way of execute each one of them.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
[[module-environment]]
Alain Reguera Delgado a76055
Module Environment
Alain Reguera Delgado a76055
------------------
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
When you execute the *centos-art.sh* script you create an execution
Alain Reguera Delgado a76055
environment in which variables and functions are defined. The
Alain Reguera Delgado a76055
execution environment is the higher environment inside *centos-art.sh*
Alain Reguera Delgado a76055
script it is considered to have a ``global'' scope, so variables and
Alain Reguera Delgado a76055
functions defined in it are always available for any function
Alain Reguera Delgado a76055
execution made from it. You can control this execution environment
Alain Reguera Delgado a76055
through the files +centos-art.sh+ and +centos-art.conf.sh+. These
Alain Reguera Delgado a76055
files don't provide too much functionality so module environments are
Alain Reguera Delgado a76055
executed inside it to extend its functionality.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
Module environments are made of small functions that perform small
Alain Reguera Delgado a76055
tasks and can be further executed in a specific order to create the
Alain Reguera Delgado a76055
desired result.  Module environments are executed and destroyed at
Alain Reguera Delgado a76055
demand.  Inside *centos-art.sh*, module environments can be either
Alain Reguera Delgado a76055
``parent modules,'' ``child modules,'' or ``sibling modules.''
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
Parent Modules
Alain Reguera Delgado a76055
~~~~~~~~~~~~~~
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
Parent modules are initiated by executing the
Alain Reguera Delgado a76055
*tcar_setModuleEnvironment* function with the *-t parent* option set
Alain Reguera Delgado a76055
on it. Parent modules are very simple in design and you can use them
Alain Reguera Delgado a76055
to implement simple solutions quickly. Normally, when you execute a
Alain Reguera Delgado a76055
parent module, you initiate the highest module environment possible
Alain Reguera Delgado a76055
inside *centos-art.sh* script.  Because of such high scope, parent
Alain Reguera Delgado a76055
modules are frequently used to define module's global variables,
Alain Reguera Delgado a76055
interpret module-specific options passed through the command-line and
Alain Reguera Delgado a76055
execute the appropriate actions based on them.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
In <<debug-parent-modules>>, we have executed the *hello* module with
Alain Reguera Delgado a76055
the *--greeting=hi* and *--debug* options through the command-line. In
Alain Reguera Delgado a76055
this example, *centos-art.sh* script executes a parent module named
Alain Reguera Delgado a76055
*hello*, processes the module-specific options passed through the
Alain Reguera Delgado a76055
command-line, prints a greeting message to standard output and exits
Alain Reguera Delgado a76055
successfully.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
[[debug-parent-modules]]
Alain Reguera Delgado a76055
.Debugging execution of parent modules
Alain Reguera Delgado a76055
======================================================================
Alain Reguera Delgado a76055
----------------------------------------------------------------------
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT =========================>      [0] | main
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT TCAR_MODULE_BASEDIR             Automation/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT TCAR_MODULE_NAME                [0]=hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT TCAR_MODULE_TYPE                parent
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT TCAR_MODULE_ARGUMENT            --greeting=hi  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT TCAR_MODULE_LIST                hello|help|locale|prepare|render|tuneup|vcs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT TCAR_MODULE_DIR                 Automation/Modules/Hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT TCAR_MODULE_DIR_MODULES         Automation/Modules/Hello/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT TCAR_MODULE_DIR_MANUALS         Automation/Modules/Hello/Manuals
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT TCAR_MODULE_DIR_LOCALES         Automation/Modules/Hello/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT TCAR_MODULE_DIR_CONFIGS         Automation/Modules/Hello/Configs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT TCAR_MODULE_INIT_FILE           Automation/Modules/Hello/hello.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT TEXTDOMAIN                      hello.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT TEXTDOMAINDIR                   Automation/Modules/Hello/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT export -f                       hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT export -f                       hello_getOptions
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT ------------------------->      hello --greeting=hi  
Alain Reguera Delgado a76055
hi             
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT <-------------------------      hello 
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT unset -f                        hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT unset -f                        hello_getOptions
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT <=========================      [0] | main
Alain Reguera Delgado a76055
----------------------------------------------------------------------
Alain Reguera Delgado a76055
======================================================================
Alain Reguera Delgado 393983
Alain Reguera Delgado a76055
<<debug-parent-modules>> describes an entire module environment in
Alain Reguera Delgado a76055
action. With this information you can create your own module
Alain Reguera Delgado a76055
environment, already. However, when your module is getting too much
Alain Reguera Delgado a76055
complicated you probably want to divide it in smaller pieces that you
Alain Reguera Delgado a76055
can execute accordingly, based on the purpose you defined for it. Such
Alain Reguera Delgado a76055
kind of division can be implemented through ``modules' related
Alain Reguera Delgado a76055
functions.''
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
Module's related functions are stored in the same directory of your
Alain Reguera Delgado a76055
module's initialization file and they are very useful when you are
Alain Reguera Delgado a76055
refactoring it.  Definitions of module's related functions are loaded
Alain Reguera Delgado a76055
before the initialization file does, so it is a good practice to
Alain Reguera Delgado a76055
create them only when you are absolutely sure they will be executed in
Alain Reguera Delgado a76055
your module. Otherwise they may be loaded and never be used, which
Alain Reguera Delgado a76055
make the script to waste memory unnecessarily. In these cases, when
Alain Reguera Delgado a76055
you need to divide the logic of a module in smaller pieces where these
Alain Reguera Delgado a76055
pieces may or may not be executed based on specific conditions, all
Alain Reguera Delgado a76055
taking place in the same interaction, then using ``_child modules_''
Alain Reguera Delgado a76055
is a more suitable approach.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
[[child-modules]]
Alain Reguera Delgado a76055
Child Modules
Alain Reguera Delgado a76055
~~~~~~~~~~~~~
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
Child modules are initiated by executing the
Alain Reguera Delgado a76055
*tcar_setModuleEnvironment* function with the *-t child* option set on
Alain Reguera Delgado a76055
it.  Child modules have the characteristic of being nested modules.
Alain Reguera Delgado a76055
They cannot be executed from the command-line. Normally, child modules
Alain Reguera Delgado a76055
are executed from parent modules but they can be executed from other
Alain Reguera Delgado a76055
child modules, too.  When several child modules are executed in one
Alain Reguera Delgado a76055
single interaction of *centos-art.sh*, they create a chain of modules.
Alain Reguera Delgado a76055
A chain of modules is very useful in situations where you want to
Alain Reguera Delgado a76055
divide one large task into smaller tasks and also control which of
Alain Reguera Delgado a76055
these smaller tasks is executed based on specific conditions (e.g.,
Alain Reguera Delgado a76055
you may want to render images or documentation, but not both, in one
Alain Reguera Delgado a76055
single interaction of *centos-art.sh* script).  In a chain of modules,
Alain Reguera Delgado a76055
lower modules in the chain (those started last) have access to
Alain Reguera Delgado a76055
information set by modules higher in the chain (those started first),
Alain Reguera Delgado a76055
but not the opposite. When processing information this way, modules
Alain Reguera Delgado a76055
aren't destroyed until the last module executed in the chain has
Alain Reguera Delgado a76055
finished its work (e.g., all the commands inside it have been
Alain Reguera Delgado a76055
executed). At that point, child modules are destroyed in the reverse
Alain Reguera Delgado a76055
order they were executed.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
For example, when you execute the *hello* module with both *--debug*
Alain Reguera Delgado a76055
and *--upper* option, *centos-art.sh* script creates a chain of three
Alain Reguera Delgado a76055
modules to produce the greeting message.  Firstly, it begins by
Alain Reguera Delgado a76055
executing the parent module named *hello*, then it continues with the
Alain Reguera Delgado a76055
child module named *output* which in turn executes the child module
Alain Reguera Delgado a76055
name *lower* to finally print the expected greeting message.  In this
Alain Reguera Delgado a76055
example, the module named *lower* is the last module in the chain of
Alain Reguera Delgado a76055
executed modules. It has access to all information defined by earlier
Alain Reguera Delgado a76055
modules (e.g., in *hello* and *output* modules) and none of its earlier
Alain Reguera Delgado a76055
modules will be destroyed until it has finished its work. This process
Alain Reguera Delgado a76055
becomes more visible when you take a look at <<debug-child-modules>>.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
[[debug-child-modules]]
Alain Reguera Delgado a76055
.Debugging execution of child modules
Alain Reguera Delgado 393983
======================================================================
Alain Reguera Delgado a76055
----------------------------------------------------------------------
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT =========================>      [0] | main
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_BASEDIR             Automation/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_NAME                [0]=hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_TYPE                parent
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_ARGUMENT            --upper --greeting=hi  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_LIST                hello|help|locale|prepare|render|tuneup|vcs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_DIR                 Automation/Modules/Hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_DIR_MODULES         Automation/Modules/Hello/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_DIR_MANUALS         Automation/Modules/Hello/Manuals
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_DIR_LOCALES         Automation/Modules/Hello/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_DIR_CONFIGS         Automation/Modules/Hello/Configs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_INIT_FILE           Automation/Modules/Hello/hello.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TEXTDOMAIN                      hello.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TEXTDOMAINDIR                   Automation/Modules/Hello/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT export -f                       hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT export -f                       hello_getOptions
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT ------------------------->      hello --upper --greeting=hi  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT =========================>      [1] | hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_BASEDIR             Automation/Modules/Hello/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_NAME                [1]=output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_TYPE                child
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_ARGUMENT             
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_LIST                output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_DIR                 Automation/Modules/Hello/Modules/Output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_DIR_MODULES         Automation/Modules/Hello/Modules/Output/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_DIR_MANUALS         Automation/Modules/Hello/Modules/Output/Manuals
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_DIR_LOCALES         Automation/Modules/Hello/Modules/Output/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_DIR_CONFIGS         Automation/Modules/Hello/Modules/Output/Configs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_INIT_FILE           Automation/Modules/Hello/Modules/Output/output.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TEXTDOMAIN                      output.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TEXTDOMAINDIR                   Automation/Modules/Hello/Modules/Output/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT export -f                       output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT ------------------------->      output  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT =========================>      [2] | output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_BASEDIR             Automation/Modules/Hello/Modules/Output/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_NAME                [2]=upper
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_TYPE                child
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_ARGUMENT             
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_LIST                camel|lower|random|upper
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_DIR                 Automation/Modules/Hello/Modules/Output/Modules/Upper
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_DIR_MODULES         Automation/Modules/Hello/Modules/Output/Modules/Upper/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT TCAR_MODULE_DIR_MANUALS         Automation/Modules/Hello/Modules/Output/Modules/Upper/Manuals
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT TCAR_MODULE_DIR_LOCALES         Automation/Modules/Hello/Modules/Output/Modules/Upper/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT TCAR_MODULE_DIR_CONFIGS         Automation/Modules/Hello/Modules/Output/Modules/Upper/Configs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT TCAR_MODULE_INIT_FILE           Automation/Modules/Hello/Modules/Output/Modules/Upper/upper.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT TEXTDOMAIN                      upper.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT TEXTDOMAINDIR                   Automation/Modules/Hello/Modules/Output/Modules/Upper/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT export -f                       upper
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT ------------------------->      upper  
Alain Reguera Delgado a76055
HI             
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT <-------------------------      upper  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT unset -f                        upper
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT <=========================      [2] | output 
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT <-------------------------      output  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT unset -f                        output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT <=========================      [1] | hello 
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT <-------------------------      hello 
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT unset -f                        hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT unset -f                        hello_getOptions
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT <=========================      [0] | main 
Alain Reguera Delgado a76055
----------------------------------------------------------------------
Alain Reguera Delgado 393983
======================================================================
Alain Reguera Delgado 393983
Alain Reguera Delgado a76055
The module environment described in <<debug-child-modules>> shows the
Alain Reguera Delgado a76055
child modules' ability of reducing scope as they get deeper in the
Alain Reguera Delgado a76055
chain of executed modules. However, child modules lack the possibility
Alain Reguera Delgado a76055
of nest modules that share the same scope. For example, in the *hello*
Alain Reguera Delgado a76055
module described above, you cannot execute the modules *lower*  or
Alain Reguera Delgado a76055
*upper* from *camel* module, as if they were child modules of it.
Alain Reguera Delgado a76055
That is not possible because they all have the same scope, which is,
Alain Reguera Delgado a76055
to print the greeting message to standard output. Child modules are
Alain Reguera Delgado a76055
conceived to reduce the module scope as new child modules are
Alain Reguera Delgado a76055
executed. When you need to execute new module environments and, also,
Alain Reguera Delgado a76055
retain the last scope from which the new module is executed, you need
Alain Reguera Delgado a76055
to use ``_sibling modules_,'' instead.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
Sibling Modules
Alain Reguera Delgado a76055
~~~~~~~~~~~~~~~
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
Sibling modules are initiated by executing the
Alain Reguera Delgado a76055
*tcar_setModuleEnvironment* function with the *-t sibling* option set
Alain Reguera Delgado a76055
on it.  Sibling modules are another type of nested modules but, in
Alain Reguera Delgado a76055
contrast with child modules, sibling modules cannot be executed from
Alain Reguera Delgado a76055
parent modules. Normally, sibling modules are executed from other
Alain Reguera Delgado a76055
sibling modules but, considering the context, they can be executed
Alain Reguera Delgado a76055
from child module too, to initiate sibling processing. When several
Alain Reguera Delgado a76055
siblings modules are executed, they also build a chain of modules. In
Alain Reguera Delgado a76055
contrast with the chain of child modules, the chain of sibling modules
Alain Reguera Delgado a76055
destroys the last sibling module executed before executing the next
Alain Reguera Delgado a76055
sibling module. This make the chain to stop its growing at sibling
Alain Reguera Delgado a76055
module processing, unless you call a child module from a sibling
Alain Reguera Delgado a76055
module. In this case, the chain expansion would continue as long as
Alain Reguera Delgado a76055
the number of child modules you execute. This process becomes more
Alain Reguera Delgado a76055
visible when you take a look at <<debug-sibling-modules>>.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
In <<debug-sibling-modules>>, we've executed the *hello* module with
Alain Reguera Delgado a76055
the *--greeting=hi*, *--camel*, and *--debug* options. In this
Alain Reguera Delgado a76055
example, *centos-art.sh* script executes the *hello* module then the
Alain Reguera Delgado a76055
*output* module which in turn executes the *camel* module. At this
Alain Reguera Delgado a76055
point, can appreciate how the chain of modules stop growing. Observe
Alain Reguera Delgado a76055
that *camel* module has gained the position 2 in the chain of modules
Alain Reguera Delgado a76055
and executes the *upper* module which takes the position 3, as
Alain Reguera Delgado a76055
expected. Now, when *upper* module finishes its work it is destroyed
Alain Reguera Delgado a76055
and the module's counter is reset to its previous value which is 2
Alain Reguera Delgado a76055
(the one set by *camel* module). Then, *camel* executes the *lower*
Alain Reguera Delgado a76055
module which take position 3 at the chain of modules until it
Alain Reguera Delgado a76055
finishes. When it finishes, the *camel* module finishes its work and
Alain Reguera Delgado a76055
is destroyed, then *output*, then *hello*.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
[[debug-sibling-modules]]
Alain Reguera Delgado a76055
.Debugging execution of sibling modules
Alain Reguera Delgado 393983
======================================================================
Alain Reguera Delgado 393983
----------------------------------------------------------------------
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT =========================>      [0] | main
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT TCAR_MODULE_BASEDIR             Automation/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT TCAR_MODULE_NAME                [0]=hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT TCAR_MODULE_TYPE                parent
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT TCAR_MODULE_ARGUMENT            --camel --greeting=hi  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT TCAR_MODULE_LIST                hello|help|locale|prepare|render|tuneup|vcs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT TCAR_MODULE_DIR                 Automation/Modules/Hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT TCAR_MODULE_DIR_MODULES         Automation/Modules/Hello/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT TCAR_MODULE_DIR_MANUALS         Automation/Modules/Hello/Manuals
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT TCAR_MODULE_DIR_LOCALES         Automation/Modules/Hello/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT TCAR_MODULE_DIR_CONFIGS         Automation/Modules/Hello/Configs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT TCAR_MODULE_INIT_FILE           Automation/Modules/Hello/hello.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT TEXTDOMAIN                      hello.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT TEXTDOMAINDIR                   Automation/Modules/Hello/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT export -f                       hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT export -f                       hello_getOptions
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT ------------------------->      hello --camel --greeting=hi  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT =========================>      [1] | hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_BASEDIR             Automation/Modules/Hello/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_NAME                [1]=output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_TYPE                child
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_ARGUMENT             
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_LIST                output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR                 Automation/Modules/Hello/Modules/Output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR_MODULES         Automation/Modules/Hello/Modules/Output/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR_MANUALS         Automation/Modules/Hello/Modules/Output/Manuals
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR_LOCALES         Automation/Modules/Hello/Modules/Output/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR_CONFIGS         Automation/Modules/Hello/Modules/Output/Configs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_INIT_FILE           Automation/Modules/Hello/Modules/Output/output.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TEXTDOMAIN                      output.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TEXTDOMAINDIR                   Automation/Modules/Hello/Modules/Output/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT export -f                       output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT ------------------------->      output  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT =========================>      [2] | output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_BASEDIR             Automation/Modules/Hello/Modules/Output/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_NAME                [2]=camel
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_TYPE                child
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_ARGUMENT             
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_LIST                camel|lower|random|upper
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR                 Automation/Modules/Hello/Modules/Output/Modules/Camel
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR_MODULES         Automation/Modules/Hello/Modules/Output/Modules/Camel/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR_MANUALS         Automation/Modules/Hello/Modules/Output/Modules/Camel/Manuals
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR_LOCALES         Automation/Modules/Hello/Modules/Output/Modules/Camel/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR_CONFIGS         Automation/Modules/Hello/Modules/Output/Modules/Camel/Configs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_INIT_FILE           Automation/Modules/Hello/Modules/Output/Modules/Camel/camel.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TEXTDOMAIN                      camel.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TEXTDOMAINDIR                   Automation/Modules/Hello/Modules/Output/Modules/Camel/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT export -f                       camel
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT ------------------------->      camel  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT =========================>      [3] | camel
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_BASEDIR             Automation/Modules/Hello/Modules/Output/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_NAME                [3]=upper
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_TYPE                sibling
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_ARGUMENT             
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_LIST                camel|lower|random|upper
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR                 Automation/Modules/Hello/Modules/Output/Modules/Upper
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR_MODULES         Automation/Modules/Hello/Modules/Output/Modules/Upper/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR_MANUALS         Automation/Modules/Hello/Modules/Output/Modules/Upper/Manuals
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR_LOCALES         Automation/Modules/Hello/Modules/Output/Modules/Upper/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR_CONFIGS         Automation/Modules/Hello/Modules/Output/Modules/Upper/Configs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_INIT_FILE           Automation/Modules/Hello/Modules/Output/Modules/Upper/upper.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TEXTDOMAIN                      upper.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TEXTDOMAINDIR                   Automation/Modules/Hello/Modules/Output/Modules/Upper/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT export -f                       upper
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT ------------------------->      upper  
Alain Reguera Delgado a76055
H              
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT <-------------------------      upper  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT unset -f                        upper
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT <=========================      [3] | camel 
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT =========================>      [3] | camel
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_BASEDIR             Automation/Modules/Hello/Modules/Output/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_NAME                [3]=lower
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_TYPE                sibling
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_ARGUMENT             
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_LIST                camel|lower|random|upper
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR                 Automation/Modules/Hello/Modules/Output/Modules/Lower
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR_MODULES         Automation/Modules/Hello/Modules/Output/Modules/Lower/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT TCAR_MODULE_DIR_MANUALS         Automation/Modules/Hello/Modules/Output/Modules/Lower/Manuals
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT TCAR_MODULE_DIR_LOCALES         Automation/Modules/Hello/Modules/Output/Modules/Lower/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT TCAR_MODULE_DIR_CONFIGS         Automation/Modules/Hello/Modules/Output/Modules/Lower/Configs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT TCAR_MODULE_INIT_FILE           Automation/Modules/Hello/Modules/Output/Modules/Lower/lower.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT TEXTDOMAIN                      lower.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT TEXTDOMAINDIR                   Automation/Modules/Hello/Modules/Output/Modules/Lower/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT export -f                       lower
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT ------------------------->      lower  
Alain Reguera Delgado a76055
i              
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT <-------------------------      lower  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT unset -f                        lower
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT <=========================      [3] | camel 
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT <-------------------------      camel  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT unset -f                        camel
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT <=========================      [2] | output 
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT <-------------------------      output  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT unset -f                        output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT <=========================      [1] | hello 
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT <-------------------------      hello 
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT unset -f                        hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT unset -f                        hello_getOptions
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT <=========================      [0] | main
Alain Reguera Delgado a76055
----------------------------------------------------------------------
Alain Reguera Delgado a76055
======================================================================
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
<<debug-sibling-modules>> shows a single interaction of
Alain Reguera Delgado a76055
*centos-art.sh* script executing different types of modules. Normally,
Alain Reguera Delgado a76055
one module is executed at some point and destroyed at the same point
Alain Reguera Delgado a76055
when it has finished its work, however, what if the next immediate
Alain Reguera Delgado a76055
module you are about to execute is the same module you are about to
Alain Reguera Delgado a76055
destroyed? This is, you need to execute the last module in the chain
Alain Reguera Delgado a76055
of executed modules again, but, this time, from itself.  In cases like
Alain Reguera Delgado a76055
this, the *centos-art.sh* script doesn't destroy the last module.  It
Alain Reguera Delgado a76055
cannot, because you are certainly executing a new module from itself,
Alain Reguera Delgado a76055
so it has to wait for this new call to finish in order to be
Alain Reguera Delgado a76055
destroyed. This kind of processing is known as _processing modules
Alain Reguera Delgado a76055
recursively._
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
Recursive Modules
Alain Reguera Delgado a76055
~~~~~~~~~~~~~~~~~
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
When one module environment executes itself we are in presence of a
Alain Reguera Delgado a76055
recursive module execution. The execution of modules recursively
Alain Reguera Delgado a76055
doesn't destroy the last module in the chain of executed modules and
Alain Reguera Delgado a76055
doesn't increment or decrement the module counter either. The module
Alain Reguera Delgado a76055
counter is somehow frozen until a different module environment is
Alain Reguera Delgado a76055
executed. In this cases, the last module environment remains in memory
Alain Reguera Delgado a76055
for the new module execution to make use of. This process becomes more visible
Alain Reguera Delgado a76055
when you take a look at <<debug-recursive-modules>>.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
[CAUTION]
Alain Reguera Delgado a76055
When you execute modules recursively, you should be very careful not
Alain Reguera Delgado a76055
to get trapped into an endless loop.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
In <<debug-recursive-modules>>, we've executed the *hello* module with
Alain Reguera Delgado a76055
the *--greeting=hello*, *--random*, and *--debug* options. In this
Alain Reguera Delgado a76055
example, *centos-art.sh* script executes a parent module named *hello*
Alain Reguera Delgado a76055
which in turn executes a child module named *output* which in turn
Alain Reguera Delgado a76055
executes a child module named *random*. At this point, the *random*
Alain Reguera Delgado a76055
modules executes itself five times (the number of characters passed as
Alain Reguera Delgado a76055
value to greeting option) to print out random letters from the
Alain Reguera Delgado a76055
greeting message. The output may have no much sense on itself but the
Alain Reguera Delgado a76055
related debugging information helps to understand the execution of
Alain Reguera Delgado a76055
modules recursively.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
[[debug-recursive-modules]]
Alain Reguera Delgado a76055
.Processing execution of modules recursively
Alain Reguera Delgado a76055
======================================================================
Alain Reguera Delgado a76055
----------------------------------------------------------------------
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:03 PM CDT =========================>      [0] | main
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:03 PM CDT TCAR_MODULE_BASEDIR             Automation/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:03 PM CDT TCAR_MODULE_NAME                [0]=hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:03 PM CDT TCAR_MODULE_TYPE                parent
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:03 PM CDT TCAR_MODULE_ARGUMENT            --random --greeting=Hello  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:03 PM CDT TCAR_MODULE_LIST                hello|help|locale|prepare|render|tuneup|vcs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:03 PM CDT TCAR_MODULE_DIR                 Automation/Modules/Hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:03 PM CDT TCAR_MODULE_DIR_MODULES         Automation/Modules/Hello/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:03 PM CDT TCAR_MODULE_DIR_MANUALS         Automation/Modules/Hello/Manuals
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_DIR_LOCALES         Automation/Modules/Hello/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_DIR_CONFIGS         Automation/Modules/Hello/Configs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_INIT_FILE           Automation/Modules/Hello/hello.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TEXTDOMAIN                      hello.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TEXTDOMAINDIR                   Automation/Modules/Hello/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT export -f                       hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT export -f                       hello_getOptions
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT ------------------------->      hello --random --greeting=Hello  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT =========================>      [1] | hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_BASEDIR             Automation/Modules/Hello/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_NAME                [1]=output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_TYPE                child
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_ARGUMENT             
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_LIST                output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_DIR                 Automation/Modules/Hello/Modules/Output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_DIR_MODULES         Automation/Modules/Hello/Modules/Output/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_DIR_MANUALS         Automation/Modules/Hello/Modules/Output/Manuals
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_DIR_LOCALES         Automation/Modules/Hello/Modules/Output/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_DIR_CONFIGS         Automation/Modules/Hello/Modules/Output/Configs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_INIT_FILE           Automation/Modules/Hello/Modules/Output/output.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TEXTDOMAIN                      output.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TEXTDOMAINDIR                   Automation/Modules/Hello/Modules/Output/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT export -f                       output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT ------------------------->      output  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT =========================>      [2] | output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_BASEDIR             Automation/Modules/Hello/Modules/Output/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_NAME                [2]=random
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_TYPE                child
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_ARGUMENT             
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_LIST                camel|lower|random|upper
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_DIR                 Automation/Modules/Hello/Modules/Output/Modules/Random
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_DIR_MODULES         Automation/Modules/Hello/Modules/Output/Modules/Random/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_DIR_MANUALS         Automation/Modules/Hello/Modules/Output/Modules/Random/Manuals
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_DIR_LOCALES         Automation/Modules/Hello/Modules/Output/Modules/Random/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_DIR_CONFIGS         Automation/Modules/Hello/Modules/Output/Modules/Random/Configs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_INIT_FILE           Automation/Modules/Hello/Modules/Output/Modules/Random/random.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TEXTDOMAIN                      random.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TEXTDOMAINDIR                   Automation/Modules/Hello/Modules/Output/Modules/Random/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT export -f                       random
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT ------------------------->      random  
Alain Reguera Delgado a76055
H              
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT ~~~~~~~~~~~~~~~~~~~~~~~~~>      random  
Alain Reguera Delgado a76055
H              
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT ~~~~~~~~~~~~~~~~~~~~~~~~~>      random  
Alain Reguera Delgado a76055
l              
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT ~~~~~~~~~~~~~~~~~~~~~~~~~>      random  
Alain Reguera Delgado a76055
l              
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT ~~~~~~~~~~~~~~~~~~~~~~~~~>      random  
Alain Reguera Delgado a76055
H              
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT <-------------------------      random  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT unset -f                        random
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT <=========================      [2] | output 
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT <-------------------------      output  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:05 PM CDT unset -f                        output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:05 PM CDT <=========================      [1] | hello 
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:05 PM CDT <-------------------------      hello 
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:05 PM CDT unset -f                        hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:05 PM CDT unset -f                        hello_getOptions
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:05 PM CDT <=========================      [0] | main 
Alain Reguera Delgado 393983
----------------------------------------------------------------------
Alain Reguera Delgado 393983
======================================================================
Alain Reguera Delgado 393983
Alain Reguera Delgado a76055
Recursive execution of modules occurs only when the module you are
Alain Reguera Delgado a76055
executing is considered sibling of the last module executed in the
Alain Reguera Delgado a76055
chain of executed modules and they both have the same name. The fact
Alain Reguera Delgado a76055
that no variable name is printed out in <<debug-recursive-modules>>
Alain Reguera Delgado a76055
means that they were not created. The change in the arrows shown in
Alain Reguera Delgado a76055
the example, from +->+ to +~>+, means that module's related functions
Alain Reguera Delgado a76055
weren't exported for the new module execution either. It also means
Alain Reguera Delgado a76055
that the initialization script is reusing both module's related
Alain Reguera Delgado a76055
functions variables from the last module's environment in the chain of
Alain Reguera Delgado a76055
executed modules. In this case *random* module itself.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
Summary
Alain Reguera Delgado a76055
~~~~~~~
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
This section has covered the module environment inside *centos-art.sh*
Alain Reguera Delgado a76055
script, including module types and possible combinations of them. The
Alain Reguera Delgado a76055
next section takes these concepts and focuses on the implementation of
Alain Reguera Delgado a76055
them. Once you finish it, you should be able of writing your own
Alain Reguera Delgado a76055
module environments from scratch inside *centos-art.sh* script.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
Module Implementation
Alain Reguera Delgado a76055
---------------------
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
Parent Modules
Alain Reguera Delgado a76055
~~~~~~~~~~~~~~
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
The <<hello-simplest-directory-structure>>, shows a basic module
Alain Reguera Delgado a76055
structure. In this example, we see that module directories are written
Alain Reguera Delgado a76055
capitalized while module initialization file and related functions are
Alain Reguera Delgado a76055
all written in lower-case. Note also how the module directory and
Alain Reguera Delgado a76055
files inside it use the module's name in their file names to get
Alain Reguera Delgado a76055
identified. This is a convention that should be followed in order for
Alain Reguera Delgado a76055
*centos-art.sh* script to execute modules. Another convention you
Alain Reguera Delgado a76055
should follow, when creating related functions, is using underscore
Alain Reguera Delgado a76055
(``_'') to separate the module's name from the function's descriptive
Alain Reguera Delgado a76055
name. In these cases, the function's descriptive name is always
Alain Reguera Delgado a76055
written in camel-case followed by the +.sh+ extension.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
[[hello-simplest-directory-structure]]
Alain Reguera Delgado a76055
.Simplest directory structure of hello module.
Alain Reguera Delgado 393983
======================================================================
Alain Reguera Delgado 393983
----------------------------------------------------------------------
Alain Reguera Delgado 393983
.
Alain Reguera Delgado a76055
|-- COPYING                     <-- Contains the GPL license.
Alain Reguera Delgado a76055
|-- Locales/                    <-- localization of all sh files.
Alain Reguera Delgado a76055
|-- Manuals/                    <-- manuals for main and global functions.
Alain Reguera Delgado a76055
|-- Modules/                    <-- top-modules are stored here.
Alain Reguera Delgado 393983
|   `-- Hello/
Alain Reguera Delgado 393983
|       `-- hello.sh
Alain Reguera Delgado a76055
|-- Scripts/                    <-- global functions are stored here.
Alain Reguera Delgado a76055
|-- centos-art.conf.sh          <-- main configuration file.
Alain Reguera Delgado a76055
`-- centos-art.sh               <-- main initialization file.
Alain Reguera Delgado 393983
----------------------------------------------------------------------
Alain Reguera Delgado 393983
======================================================================
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
The module's initialization file contains the main function definition
Alain Reguera Delgado 393983
of your module. It is a good place to define variables that must be
Alain Reguera Delgado 393983
always available inside the module. There is also a top-comment that
Alain Reguera Delgado 393983
collects information about the function files you are writing (e.g., a
Alain Reguera Delgado 393983
small description, a written by section, the copyright note and the
Alain Reguera Delgado 393983
legal status of the file). Even using a top comment like this is not
Alain Reguera Delgado 393983
required for *centos-art.sh* script to execute modules properly, it is
Alain Reguera Delgado 393983
very useful as matter of consistency and style inside it (and the
Alain Reguera Delgado 393983
copyright and legal notice might be required for legal protection of
Alain Reguera Delgado 393983
your code as set by GPL).  Finally, there is the function definition
Alain Reguera Delgado a76055
named +hello+ just as the directory that holds it but all in lower.
Alain Reguera Delgado 393983
Inside this function definition is where we write what we want the
Alain Reguera Delgado 393983
*hello* module does for us. This way, following with the *hello* example,
Alain Reguera Delgado 393983
we create an array variable inside it holding all the suggestions we
Alain Reguera Delgado 393983
would like to print, as described in <<initialization-file>>.
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
[[initialization-file]]
Alain Reguera Delgado 393983
.The initialization file of hello module
Alain Reguera Delgado 393983
======================================================================
Alain Reguera Delgado 393983
----------------------------------------------------------------------
Alain Reguera Delgado 393983
#!/bin/bash
Alain Reguera Delgado 393983
######################################################################
Alain Reguera Delgado 393983
#
Alain Reguera Delgado 393983
#   hello.sh -- Print out greetings to standard output and exit
Alain Reguera Delgado 393983
#   successfully.
Alain Reguera Delgado 393983
#
Alain Reguera Delgado 393983
#   Written by:
Alain Reguera Delgado 393983
#   * Alain Reguera Delgado <al@centos.org.cu>, 2013
Alain Reguera Delgado 393983
#
Alain Reguera Delgado 393983
# Copyright (C) 2009-2013 The CentOS Artwork SIG
Alain Reguera Delgado 393983
#
Alain Reguera Delgado 393983
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 393983
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 393983
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 393983
# your option) any later version.
Alain Reguera Delgado 393983
#
Alain Reguera Delgado 393983
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 393983
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 393983
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 393983
# General Public License for more details.
Alain Reguera Delgado 393983
#
Alain Reguera Delgado 393983
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 393983
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 393983
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 393983
#
Alain Reguera Delgado 393983
######################################################################
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
function hello {
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
    tcar_printMessage "Hello, World!"
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
}
Alain Reguera Delgado 393983
----------------------------------------------------------------------
Alain Reguera Delgado 393983
======================================================================
Alain Reguera Delgado 393983
Alain Reguera Delgado a76055
Child Modules
Alain Reguera Delgado a76055
~~~~~~~~~~~~~
Alain Reguera Delgado a76055
...
Alain Reguera Delgado 393983
Alain Reguera Delgado a76055
Sibling Modules
Alain Reguera Delgado a76055
~~~~~~~~~~~~~~~
Alain Reguera Delgado 393983
Alain Reguera Delgado a76055
...
Alain Reguera Delgado 393983
Alain Reguera Delgado a76055
Recursive Modules
Alain Reguera Delgado a76055
~~~~~~~~~~~~~~~~~
Alain Reguera Delgado 393983
Alain Reguera Delgado a76055
...
Alain Reguera Delgado 393983
Alain Reguera Delgado a76055
Summary
Alain Reguera Delgado a76055
~~~~~~~
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
...
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
// vim: set syntax=asciidoc: