While a public yum repository is easy to set up with S3, going private is more difficult. The privacy must be enforced by some plugin that can retrieve files from the S3 bucket with the API using stored credentials (maybe). Storing credentials can be avoided on EC2 machines that are assigned a proper role, but this is not possible in any other scenario.
Nevertheless, the first steps are common for both public and private setups:
1. Create the proper directory structure
This is achievable with the “createrepo” binary that can be installed on both RedHat and Debian-based systems (e.g. Fedora/Centos or Ubuntu). Running this program results in a “repodata” sub-directory being created with a couple of files that store parsed rpm information.
2. Sync the local repository with the S3 bucket
… is ignoring the run order of the scriptlets. Because you may want to arrive to a result close to this one:
When installing the rpm for the first time, add the service to chkconfig and get it in the running state;
When removing (for good), stop the service and remove it from chkconfig;
When upgrading, stop the current running service, do the binary upgrade and start the new service (do not alter chkconfig).
A quick approach to this would ignore the upgrade part completely, hoping that coupling together the removal and the installation would do the trick. Something like the following in the .spec file:
%post chkconfig --add mywow service mywow start %preun service mywow stop chkconfig --del mywow
This will actually do the job if installation and removal of the rpm package were the only operations to be considered. The problem is that during an upgrade this will go horribly wrong as the scriptlet running order is different than the one expected by the previous sample:
%pre of the new package
%post of the new package
%preun of the old package
%postun of the old package
The obvious result is that an upgrade with those scriptlets will leave the service stopped and out of chkconfig. A real disaster.
The solution is to look for the first parameter that gets passed when running each scriptlet. The rpm program passes a certain value to indicate if it’s an installation / removal or an upgrade. Considering that value we can write some better scripts:
%post if [ $1 -gt 1 ] ; then service mynow restart else chkconfig --add mywow service mywow start fi %preun if [ $1 -eq 0 ] ; then service mynow stop chkconfig --del mywow fi
Fixed. Now we are good with this.
Hope you enjoyed it!