I wanted to document this particular problem because it took me a few days to figure out and was very frustrating.
So first some background information for those new to AppFirst. In order to collect the amount of data that we do, we deploy a collector program on our customer’s servers which are ultimately built via RPMs. Whenever a customer first requests a collector, we build that custom package for them in real time and send it back to them. Simple enough right? Well here’s where things get out of whack.
We had recently made the switch from CentOS 5 to CentOS 6. Everything was more or less working as expected except (wouldn’t you guess it) rpmbuild. We had a shell script called “blah.sh” that ran rpmbuild and made sure it was pointing to all the correct files/directories and that was run using python’s subprocess module. Before I continue let me first list the system we were on.
- CentOS 6.4 (previously CentOS 5.8)
- python 2.6.6
- rpmbuild 4.8 (previously rpmbuild 4.4.2
Every time blah.sh was run with subprocess it kept exiting out with status 1 so my first assumption was to just print out it’s stdout. Refer below for code snippet on how to do this.
proc = subprocess.Popen(["./blah.sh"], stdout=subprocess.PIPE) logger.error(proc.communicate())
Calling “communicate” will display all the stdout messages and any error message that may pop up as well in the following format: (
('Building target platforms: x86_64\nBuilding for target x86_64\n', None)
Now what’s really interesting is that this script runs fine through the command line so I went through many steps to see what the actual difference was. I validated that the user was the same, the same environment variables, I tested to see if subprocess was the issue, and so on.
What it ultimately boiled down to was a permissions error. v4.8 of rpmbuild will no longer use /usr/src/redhat and instead default to /root/rpmbuild. And since you are doing this from an apache server (assuming you are not running apache as root user which is a huge security risk), apache will automatically block anything that is trying to access the root directory which caused the entire script to fail out with exit 1. To fix this, modify the rpmbuild line to define __topdir as a folder you have permission to write to. Refer to this link to set up your system accordingly.
This link above tells you to update your .rpmmacros file but these settings will unfortunately not get loaded in this specific scenario so you’ll have to either modify the .spec file or define it in the commandline argument. I chose the latter so here was my solution. Note that this is the contents of blah.sh
cwd='pwd' rpmbuild --define "_topdir /home/sample_home/rpmbuild/" --bb $cwd/sample.spec --target x86_64
And that should solve your problem. Hopefully this made your transition from CentOS 5 to 6 much smoother. Until next time.