Skip to content

Commit 449ff97

Browse files
yadvrRohit Yadav
authored andcommitted
packaging: Improve post-upgrade processing
$1 is "2" during package upgrade in %post section, this fixes the handling of $1 as per https://fedoraproject.org/wiki/Packaging:Scriptlets This improves handling of $1 during %post upgrade step. Some of the command/code are idempotent such as enabling and starting a service and can be run without any $1 checks. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent aa8a721 commit 449ff97

2 files changed

Lines changed: 19 additions & 22 deletions

File tree

packaging/centos63/cloud.spec

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,8 @@ if [ "$1" == "2" ] ; then
434434
fi
435435

436436
%post management
437-
if [ "$1" == "1" ] ; then
438-
/sbin/chkconfig --add cloudstack-management > /dev/null 2>&1 || true
439-
/sbin/chkconfig --level 345 cloudstack-management on > /dev/null 2>&1 || true
440-
fi
437+
/sbin/chkconfig --add cloudstack-management > /dev/null 2>&1 || true
438+
/sbin/chkconfig --level 345 cloudstack-management on > /dev/null 2>&1 || true
441439

442440
grep -s -q "db.cloud.driver=jdbc:mysql" "%{_sysconfdir}/%{name}/management/db.properties" || sed -i -e "\$adb.cloud.driver=jdbc:mysql" "%{_sysconfdir}/%{name}/management/db.properties"
443441
grep -s -q "db.usage.driver=jdbc:mysql" "%{_sysconfdir}/%{name}/management/db.properties" || sed -i -e "\$adb.usage.driver=jdbc:mysql" "%{_sysconfdir}/%{name}/management/db.properties"
@@ -522,18 +520,19 @@ if [ -d "%{_sysconfdir}/cloud" ] ; then
522520
fi
523521

524522
%post agent
525-
if [ "$1" == "1" ] ; then
523+
if [ "$1" == "2" ] ; then
526524
echo "Running %{_bindir}/%{name}-agent-upgrade to update bridge name for upgrade from CloudStack 4.0.x (and before) to CloudStack 4.1 (and later)"
527525
%{_bindir}/%{name}-agent-upgrade
528-
if [ ! -d %{_sysconfdir}/libvirt/hooks ] ; then
529-
mkdir %{_sysconfdir}/libvirt/hooks
530-
fi
531-
cp -a ${RPM_BUILD_ROOT}%{_datadir}/%{name}-agent/lib/libvirtqemuhook %{_sysconfdir}/libvirt/hooks/qemu
532-
/sbin/service libvirtd restart
533-
/sbin/chkconfig --add cloudstack-agent > /dev/null 2>&1 || true
534-
/sbin/chkconfig --level 345 cloudstack-agent on > /dev/null 2>&1 || true
535526
fi
536527

528+
if [ ! -d %{_sysconfdir}/libvirt/hooks ] ; then
529+
mkdir %{_sysconfdir}/libvirt/hooks
530+
fi
531+
cp -a ${RPM_BUILD_ROOT}%{_datadir}/%{name}-agent/lib/libvirtqemuhook %{_sysconfdir}/libvirt/hooks/qemu
532+
/sbin/service libvirtd restart
533+
/sbin/chkconfig --add cloudstack-agent > /dev/null 2>&1 || true
534+
/sbin/chkconfig --level 345 cloudstack-agent on > /dev/null 2>&1 || true
535+
537536
# if saved configs from upgrade exist, copy them over
538537
if [ -f "%{_sysconfdir}/cloud.rpmsave/agent/agent.properties" ]; then
539538
mv %{_sysconfdir}/%{name}/agent/agent.properties %{_sysconfdir}/%{name}/agent/agent.properties.rpmnew

packaging/centos7/cloud.spec

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,7 @@ if [ "$1" == "2" ] ; then
392392
fi
393393

394394
%post management
395-
if [ "$1" == "1" ] ; then
396-
/usr/bin/systemctl on cloudstack-management > /dev/null 2>&1 || true
397-
fi
395+
/usr/bin/systemctl on cloudstack-management > /dev/null 2>&1 || true
398396

399397
grep -s -q "db.cloud.driver=jdbc:mysql" "%{_sysconfdir}/%{name}/management/db.properties" || sed -i -e "\$adb.cloud.driver=jdbc:mysql" "%{_sysconfdir}/%{name}/management/db.properties"
400398
grep -s -q "db.usage.driver=jdbc:mysql" "%{_sysconfdir}/%{name}/management/db.properties" || sed -i -e "\$adb.usage.driver=jdbc:mysql" "%{_sysconfdir}/%{name}/management/db.properties"
@@ -424,16 +422,16 @@ if [ -d "%{_sysconfdir}/cloud" ] ; then
424422
fi
425423

426424
%post agent
427-
if [ "$1" == "1" ] ; then
425+
if [ "$1" == "2" ] ; then
428426
echo "Running %{_bindir}/%{name}-agent-upgrade to update bridge name for upgrade from CloudStack 4.0.x (and before) to CloudStack 4.1 (and later)"
429427
%{_bindir}/%{name}-agent-upgrade
430-
if [ ! -d %{_sysconfdir}/libvirt/hooks ] ; then
431-
mkdir %{_sysconfdir}/libvirt/hooks
432-
fi
433-
cp -a ${RPM_BUILD_ROOT}%{_datadir}/%{name}-agent/lib/libvirtqemuhook %{_sysconfdir}/libvirt/hooks/qemu
434-
/sbin/service libvirtd restart
435-
/sbin/systemctl enable cloudstack-agent > /dev/null 2>&1 || true
436428
fi
429+
if [ ! -d %{_sysconfdir}/libvirt/hooks ] ; then
430+
mkdir %{_sysconfdir}/libvirt/hooks
431+
fi
432+
cp -a ${RPM_BUILD_ROOT}%{_datadir}/%{name}-agent/lib/libvirtqemuhook %{_sysconfdir}/libvirt/hooks/qemu
433+
/sbin/service libvirtd restart
434+
/sbin/systemctl enable cloudstack-agent > /dev/null 2>&1 || true
437435

438436
# if saved configs from upgrade exist, copy them over
439437
if [ -f "%{_sysconfdir}/cloud.rpmsave/agent/agent.properties" ]; then

0 commit comments

Comments
 (0)