2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-21 19:22:05 +00:00

support args in postinstallscripts (#5462)

* support args in postinstallscripts

* add the script to inject systemd service unit
This commit is contained in:
yangsong 2018-08-17 11:23:56 +08:00 committed by Bin Xu
parent dcaa21aa13
commit ebc04e4cbc
5 changed files with 42 additions and 7 deletions

View File

@ -92,7 +92,7 @@ linuximage Attributes:
\ **postinstall**\
Supported in diskless image only. The fully qualified name of the scripts running in non-chroot mode after the package installation but before initrd generation during genimage. If multiple scripts are specified, they should be seperated with comma ",". A set of osimage attributes are exported as the environment variables to be used in the postinstall scripts:
Supported in diskless image only. The fully qualified name of the scripts and the user-specified arguments running in non-chroot mode after the package installation but before initrd generation during genimage. If multiple scripts are specified, they should be seperated with comma ",". The arguments passed to each postinstall script include 4 implicit arguments(<rootimage path>,<os version>,<os arch>,<profile>) and the user-specified arguments. A set of osimage attributes are exported as the environment variables to be used in the postinstall scripts:
.. code-block:: perl

View File

@ -815,7 +815,7 @@ passed as argument rather than by table value',
otherpkglist => 'The fully qualified name of the file that stores non-distro package lists that will be included in the image. It could be set to multiple paths. The multiple paths must be separated by ",".',
otherpkgdir => 'The base directory and urls of internet repos from which the non-distro packages are retrived. Only 1 local directory is supported at present. The entries should be delimited with comma ",". Currently, the internet repos are only supported on Ubuntu and Redhat.',
exlist => 'The fully qualified name of the file that stores the file names and directory names that will be excluded from the image during packimage command. It is used for diskless image only.',
postinstall => 'Supported in diskless image only. The fully qualified name of the scripts running in non-chroot mode after the package installation but before initrd generation during genimage. If multiple scripts are specified, they should be seperated with comma ",". A set of osimage attributes are exported as the environment variables to be used in the postinstall scripts:
postinstall => 'Supported in diskless image only. The fully qualified name of the scripts and the user-specified arguments running in non-chroot mode after the package installation but before initrd generation during genimage. If multiple scripts are specified, they should be seperated with comma ",". The arguments passed to each postinstall script include 4 implicit arguments(<rootimage path>,<os version>,<os arch>,<profile>) and the user-specified arguments. A set of osimage attributes are exported as the environment variables to be used in the postinstall scripts:
IMG_ARCH(The architecture of the osimage, such as "ppc64le","x86_64"),
IMG_NAME(The name of the osimage, such as "rhels7.3-ppc64le-netboot-compute"),

View File

@ -195,7 +195,8 @@ sub process_request {
}
$postinstall_filename = $ref_linuximage_tab->{'postinstall'};
if ($postinstall_filename ne "") {
foreach my $file (split ',', $postinstall_filename) {
foreach my $rawfile (split ',', $postinstall_filename) {
my ($file,@args)=split(" ",$rawfile);
if (!-r $file) {
$callback->({ error => ["The postinstall_filename specified \'$file\' does not exist!"], errorcode => [1] });
return 1;
@ -325,7 +326,7 @@ sub process_request {
if ($pkglist) { $cmd .= " --pkglist $pkglist"; }
if ($srcdir_otherpkgs) { $cmd .= " --otherpkgdir \"$srcdir_otherpkgs\""; }
if ($otherpkglist) { $cmd .= " --otherpkglist $otherpkglist"; }
if ($postinstall_filename) { $cmd .= " --postinstall $postinstall_filename"; }
if ($postinstall_filename) { $cmd .= " --postinstall \"$postinstall_filename\""; }
if ($destdir) { $cmd .= " --rootimgdir $destdir"; }
if ($tempfile) {
if (!$dryrun) { $cmd .= " --tempfile $tempfile"; }

View File

@ -771,7 +771,6 @@ unless ($imagename) {
$postinstall_filename = imgutils::get_profile_def_filename($osver, $profile, $arch, $pathtofiles, "postinstall");
}
}
if ($postinstall_filename) {
use_hackuname($arch, $kernelver);
@ -792,14 +791,15 @@ if ($postinstall_filename) {
$ENV{IMG_ROOTIMGDIR}=$rootimg_dir if("" ne $rootimg_dir);
foreach my $postinstall (split /,/, $postinstall_filename) {
foreach my $rawpostinstall (split /,/, $postinstall_filename) {
my ($postinstall,@args)=split(" ",$rawpostinstall) ;
if (!-x $postinstall) {
print "postinstall script $postinstall is not executable\n";
unuse_hackuname();
exit 1;
}
my $rc = system($postinstall, $rootimg_dir, $osver, $arch, $profile);
my $rc = system($postinstall, $rootimg_dir, $osver, $arch, $profile,@args);
if ($rc) {
print "postinstall script $postinstall failed\n";
unuse_hackuname();

34
xCAT/postscripts/injectservice Executable file
View File

@ -0,0 +1,34 @@
#!/bin/bash
#4 implicit arguments passed by genimage
rootimg_dir=$1
osver=$2
arch=$3
profile=$4
#user-specified arguments in "postinstall" attribute
#the name of the service to inject
servicename=$5
#the full path of the service unit file to inject on management node(non-chroot)
servicefile=$6
echo servicename=$servicename
echo servicefile=$servicefile
#append the suffix ".service" to service name if not specified
echo "$servicename" |grep -q -e "\.service$" || servicename=$servicename.service
if [ -e "$rootimg_dir/usr/lib/systemd/" ]; then
#if systemd is the service management framework for the diskless image
#enable the xcatpostinit1.service
destfile="$rootimg_dir/etc/systemd/system/$servicename"
if [ -e "$rootimg_dir/etc/systemd/system/$servicename" ]; then
rm -rf $destfile
fi
cp -f $servicefile $destfile
rm -rf "$rootimg_dir/etc/systemd/system/multi-user.target.wants/$servicename"
oldpwd=$(pwd)
cd $rootimg_dir/etc/systemd/system/multi-user.target.wants/
ln -s ../$servicename "$rootimg_dir/etc/systemd/system/multi-user.target.wants/$servicename"
cd $oldpwd
fi