ContribsUpdateEvent

From SME Server
Jump to navigation Jump to search


Background

For SME10 yum has been enhanced to look for an update event for an rpm that is being installed with the name <rpmname>-update. This is then run after the install, giving the developer the opportunity to configure the system and avoid the "post-upgrade;reboot" that has been needed in the past.

yum will suppress the "configure required" message if this event is found.

For example

Installing smeserver-dhcpmanager, yum will look for and run an event that is called smeserver-dhcpmanager-update.

This is expected to be found in the events directory and take the usual event format of the sub directories "templates2expand" and "services2adjust" (if required) plus files for each action required.

[root@mailserver ~]# ls /etc/e-smith/events/smeserver-dhcpmanager-update
S10systemd-default  S50systemd-reload  templates2expand
[root@mailserver ~]#

yum will display a configuration and reboot required message if this directory does not exist.

Using createlinks to create the -update event

The normal way to create the -update event is to use the creatlinks file usually found on the top level of the data in the rpm. This is executed by a line in the spec file under the build directive:

%build
perl createlinks

SME10 provides a perl package esmith:Build:Createlinks which does all the hard work of creating the events and other associated structures.

This is the top of a typical createlinks file:

#! /usr/bin/perl -w
use esmith::Build::CreateLinks qw(:all);
panel_link("dhcpd", "manager");

Note the panel link call to create an entry in the Server manager menu. This may not be required.

and the -update event is created as follows:

 # our event specific for updating with yum without reboot
 $event = "smeserver-dhcpmanager-update";
 #add here the path to your templates needed to expand
 #see the /etc/systemd/system-preset/49-koozali.preset should be present for systemd integration on all you yum update event
 foreach my $file (qw(
                   /etc/systemd/system-preset/49-koozali.preset
                   <other template expansion here>
                  ))
                 {templates2events( $file, $event );
 }
 #action needed in case we have a systemd unit
 event_link("systemd-default", $event, "10");
 event_link("systemd-reload", $event, "50");
 #action specific to this package
 #event_link("some event", $event, "30");
 #services we need to restart
 #safe_symlink("restart", "root/etc/e-smith/events/$event/services2adjust/some service");

Uncomment (and duplicate if necessary) any lines that are required.

The Build:Createlinks package has other useful routines as well.

Other ways to create the -update event

In the extreme case where no action is required, but you want to suppress the post-upgrade;reboot message, then you can create the event directory using mkdir -p in the .spec file, but leave the contents empty. This can be done under the %setup directive as follows:

%setup
%patch1 -p1
...snip...
%patch6 -p1
mkdir -p root/etc/e-smith/events/smeserver-qmHandle-update
%build

The other alternative is to add the directories and contents in the data tree for the rpm. This is not recommended in case the structure changes.

Creating the -update event at the command line

Scripts to create the -update event and associated updates to the spec file are shown here in-case they prove useful:

Update the changelog in the spec file

[brianr@smebuild ~]$ cat bin/editcontrib-spec1 
#!/bin/bash
cd ~/smecontribs/rpms/$1/contribs10;pwd;ls;rm -f $1.spec;prepa;
BogusDateBot.sh $1.spec
changelog $1.spec
BUGNO=$(cat ~/bugzillas.csv | grep "$1" | awk -F',' '{print $5}')
echo "Found bug $BUGNO"
sed -i -c  's/\- fix/- Add Update event to createlinks/' $1.spec
sed -i -c "s/\[SME: \]/[SME: $BUGNO]/" $1.spec
vim -R $1.spec
[brianr@smebuild ~]$ 

Update the createlinks file

[brianr@smebuild ~]$ cat bin/editcontrib-createlinks1 
#!/bin/bash
#edit-createlinks1
cd ~/smecontribs/rpms/$1/contribs10;pwd;ls;
TREEDIR=$(find . -name 'createlinks' | grep -v 'old')
cd $(dirname $TREEDIR);pwd
sed -i -c "/#! *\/usr\/bin\/perl/a\\
use esmith::Build::CreateLinks qw(:all);\\
# our event specific for updating with yum without reboot\\
\$event = '$1-update';\\
#add here the path to your templates needed to expand\\
#see the /etc/systemd/system-preset/49-koozali.preset should be present for systemd integration on all you yum update event\\
\\
foreach my \$file (qw(\\
               /etc/systemd/system-preset/49-koozali.preset\\
))\\
{\\
    templates2events( \$file, \$event );\\
}\\
#action needed in case we have a systemd unit\\
event_link('systemd-default', \$event, '10');\\
event_link('systemd-reload', \$event, '50');\\
#action specific to this package\\
#event_link('action', \$event, '30');\\
#services we need to restart\\
#safe_symlink('restart',"root/etc/e-smith/events/\$event/services2adjust/service");\\
#and Server Manager panel link\\
#panel_link('somefunction', 'manager');\\
\\
" createlinks
vim -R createlinks
[brianr@smebuild ~]$

Generate Patch and Update spec file

[brianr@smebuild ~]$ cat bin/editcontrib-patch 
#!/bin/bash
# Editcontrib-patch
cd ~/smecontribs/rpms/$1/contribs10;pwd;
FOLDER=$(find . -type d -name "$1*" | grep -v "old" | grep -v "el7_sme")
FOLDER=$(echo $FOLDER | sed 's?./??')
echo $FOLDER
patchit.sh $FOLDER 'Add-Update-event-to-createlinks'
PATCHFILE=$(ls *.patch | grep "Add-Update-event-to-createlinks")
vim -R $PATCHFILE
echo $PATCHFILE
RELEASE=$(cat $1.spec | grep -i "%define release" | awk -F " " '{print $3}')
sed -i -c  "/Source:/a \\
Patch$RELEASE: $PATCHFILE" $1.spec 
sed -i -c  "/%setup/a \\
%patch$RELEASE -p1" $1.spec
vim -R $1.spec
[brianr@smebuild ~]$ 
Patch script
[brianr@smebuild ~]$ cat bin/patchit.sh 
#!/bin/sh
#
# Generate a patch file
# $1 directory name (without the old)
# $2 name of the patch file (sans .patch)
#
diff -urN $1.old/ $1/ >$1-$2.patch
ls -l $1-$2.patch
[brianr@smebuild ~]$

Note that not all of these work everytime, due to variations in the naming of sub directories etc, the calls to vim allow the user to eyeball and edit the results of the scripts.