Prepost usage
From Grid5000
A page intended to users, helping them to build prepost-aware environments.
Contents |
Tuning postinstall's script
Postinstall's script is intended to be put inside a postinstall's archive with template files to get this postinstall prepost-aware. This script loads variables files, which were unpacked during preinstall, and then do things to transform site-independent deployed system into a site-specific one.
In most cases, the environment, whose postinstall's script want to be edited, is already prepost-aware. So tuning postinstall's script boils down to retrieve existing script and editing it. If you are creating a prepost-aware postinstall from scratch, you can retrieve the default script, called prepostinst, from the SVN repository at InriaGforge.
By editing the script, you have a complete control of what is done by prepost. For example, you can avoid the copy of the site-specific preinstall files on the deployed system by removing the portion of code that do this copy. So the script can fit your very own needs but this tuning is not necessary for each environment creation. The default script fills all the basic needs and creation of new postinstall mostly consist of building site-independent templates.
| Warning | |
|---|---|
Be aware that the deployment environment, used to install the deployed environment on destination nodes, only contains few binaries. So all the code you add to postinstall's script must restrict itself to the list of available binaries. You are advised to keep the same requirements as the default prepost-aware script. | |
Building site-independent templates
Site-independent templates are configuration files where site's specificities are replaced by references to corresponding prepost variable. Into the postinstall archive, these files are located under the dest directory and are organized as a Linux data tree.
In most cases, the environment, whose postinstall's templates want to be edited, is already prepost-aware. So building site-independent templates boilds down to add some files into the existing data tree. If you are creating a prepost-aware postinstall from scratch, you have to initialize the dest directory and the needed data tree.
For instance, the postinstall of the Sid-x64-base-1.0 environment uses the following data tree:
destdest/etcdest/etc/fstabdest/etc/aptdest/etc/apt/sources.list dest/etc/environment dest/etc/iftab dest/etc/inittab dest/etc/securetty
You can add whatever branch you want in the data tree. For instance, if you need a site-specific BASH configuration file for root, add the following directory and file:
dest/root
dest/root/.bashrc
In template file, site specificities are replaced by references to variables. You can use all the available prepost variables to build our own template files. References to variables are made by enclosing variable's name between <[ and ]>.
In our previous example, we would like root's BASH configuration to be site-specific. We want the name of the current site to be displayed on the command prompt. To achieve that, dest/root/.bashrc must set the PS1 the following way:
PS1='\u@\h.<[SITE]>:\w\$ '
Adding your own stuff
Of course files added to the postinstall do not necessary need to be prepost template file. If you are used to install your scripts or whatever via postinstall, you can still do it with prepost.
The dest directory may contain files that are not template files. Actually, during prepostinst run, template files of the dest directory are transformed into site-specific files, then the whole content of the directory is copied to the deployed system. So you can consider to install, for instance, a binary named foo by putting following data sub-tree into postinstall's archive:
dest/usrdest/usr/sbindest/usr/sbin/foo
You can even put tarballs into postinstall archive and unpack them via postinstall's script. For instance, you still want your foo binary to be installed on deployed system, but this time you do not want to add a data sub-tree into the dest directory because you already have packed it into a tarball named foo.tgz. What you can do is to put the tarball at the root of the postinstall archive and add the following piece of code at the end of the postinstall's script:
tar xzf $POST_DIR/foo.tgz
Packing postinstall archive
If you have tuned the script, built template files or prepare our own stuff. It is now time to pack the whole thing into a tarball archive.
Creating directories
If the postinstall you try to build is made from scratch, few directories must be initialized:
mkdirpostinstallmkdirpostinstall/dest
Installing script
If you have your own postinstall's script: install it and link it, to help the deployment process to find it:
postinstall$cppath/to/mypostscript .postinstall$ln-s mypostscript traitement.ash
Installing files
You have your own data tree: install it:
postinstall$cp-r path/to/mydest/* dest/
Installing stuff
Install your own stuff as you treat it in your postinstall's script:
postinstall$cppath/to/mystuff/* .
Packing it
At last, pack the built postinstall tree:
postinstall$tarcvfz ../postinstall.tgz .
Testing it
Except for testing the prepost installation on a given site, there is no specific suite to test a prepost-aware postinstall.
You have to provide your own test suite. To proceed we advise you to:
- list the component you provide through the postinstall
- create a test for each of these component that checks the good installation on the resulting system
- apply the developped test suite to a deployed system
