Differences between revisions 6 and 7
Revision 6 as of 2010-12-11 07:40:47
Size: 3754
Editor: sreddy
Comment: Corrected a typo
Revision 7 as of 2011-08-26 04:10:18
Size: 3754
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

Please check the status of this specification in Launchpad before editing it. If it is Approved, contact the Assignee or another knowledgeable person before making changes.

Summary

This specification aims at providing a way to set up an environment for all scripts in a job file. This is done by adding a script section containing a shell script that will be executed before any other script.

Rationale

This feature is needed because if someone wants to define a shell function or a variable that will be used in all the scripts of a job file, he/she will need either to copy the declaration at the beginning of all scripts or will need to put these declarations in another file and source it at the beginning of each script. The solution proposed here will simplify that by not having to copy and paste the same code many times.

Use cases

  • Often SystemV init scripts are configured by shell scripts sourced before the script. You should be able to source a script once and not have to source it in every script.
  • Some distros use shell functions for starting and stopping the network. You should be able to define these functions once at the beginning of the file and use them everywhere else.

Scope

Design

It will be possible to write scripts inside a new section that begins with common script and ends with end script. This script will be executed before any other script and in the same environment. For example:

common script
    source /etc/rc.conf
    ifup(){
        ...
    }
    ifdown(){
        ...
    }
end script

post-start script
    for if in $INTERFACES; do
        ifup $if
    done
end script

Implementation

Code

No idea ... sorry.

ScottJamesRemnant: not that difficult, it could be done by simply concatenating the scripts in job_run_process, it may be easier if we force the /dev/fd/NNN trick, but it's possible either way.

Data preservation and migration

These changes are backwards compatible with the previous behaviour.

Unresolved issues

Maybe it could be possible to add a common script that will be sourced after any other script that would for example clean temporary files created in the common script that ran at the beginning. But it is not necessary because this cleanup can be written in a shell function that is easily called at the end of all other scripts.

ScottJamesRemnant: interaction with exec?


CommonScript (last edited 2011-08-26 04:10:18 by localhost)