Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a basic RPM question. I don't know very much about RPM building, besides the basic .rpmmacros file, the build directory etc. I work at a company where there is a continuous build server (Jenkins) where the Ops department wants self contained RPMs to be dropped for deployment. This is the first time I've been exposed to this methodology, and so now I need to understand the "nitty gritty" of building an RPM. I feel like if I understand the most basic spirit of the rpmbuild logic, I can take it from there, but have had a difficult time finding tutorials or documentation that elucidate the process.

So, basically I have boiled it down to a simple how do I do these three simple things type question that I think will lift the veil on RPM building.

The starting point is a .spec file, and a couple of files to be deployed.

Name:           my-ws
Version:        0.1.0
Release:        1
Summary:        A web service to do cool stuff 
URL:            http://my.ws/
BuildRoot:      %{_tmppath}/my-ws-build-root
Requires:       some-web-server-such-as-Jetty

%description
my-ws war file and data update script

%prep
%build
%install
%pre
%preun
%postun
%clean
%files
%defattr(-,www-data,www-data,-)
%doc

Now the web service is really comprised of 3 pieces of code: A python script that updates a data file, a .war file that defines the routes and does some calculations in Java, and a cronjob to run the python script once daily and restart a server, possibly Jetty.

So somewhere in this spec file I think i need to code the following logic:

To install this rpm
   copy the python script my-ws-update.py to /opt/my-ws/bin and chown it to www-data
   copy the war file my-ws.war to /opt/webapps
   install a cronjob for www-data to run my-ws-update.py and restart some server

To uninstall this rpm
   undo install steps

Starting with an empty spec file I have no idea where to go next. I've tried a few tutorials but none seem to be aimed at this kind of simple, fundamental level. I have a feeling the %files directive is one key to all this, but when I look at other peoples examples, all I see is a list of directories, and its not clear to me how the rpm knows to put file x from path y to file w in path z.

Can anyone help me understand the basic nuts and bolts of doing this? This will be something I need to do many times at least over the next year so help is much appreciated!

A more advanced version of this will eventually be to install the cronjobs at staggered times across servers, to avoid downtime.

share|improve this question

1 Answer 1

First you need the files you want to install on the systems. Putting them in a tar.gz would be OK. Then add the following in the prep section:

%prep
%setup -q

It will untar your tar.gz to rpmbuild/BUILD and cd to your directory.

At the install section put simple commands to copy the files from BUILD/mydir under BUILDROOT with the same hierarcy you want with the installed files.

%install
rm -rf $RPM_BUILD_ROOT
install -d $RPM_BUILD_ROOT/dir/to/create
cp -a my-ws-update.py $RPM_BUILD_ROOT/dir/to/create
etc...

Finally you have to list files you want in your rpm file. If you list a file, which was not copied to $RPM_BUILD_ROOT or copy files without listing them, rpmbuild will warn you. For example:

error: Installed (but unpackaged) file(s) found:
    /etc/redhat-release
    /etc/system-release

You SHOULD write the changelog section too, e.g.

%changelog
* Tue Jan 08 2013 Dennis Gilmore <dennis@ausil.us> - 17-2
- add the fedora 18 GPG keys

After finishing spec file, build rpm:

rpmbuild -ba myfile.spec

It will create the binary and source rpms as well. Source rpm is named src.rpm which will contain all source files and spec files needed to recreate rpm.

I hope it helped.

What system are you building rpms on? I can give you more details, if you want. :)

share|improve this answer
    
Hi, thanks for chiming in. This is helping get closer to the finish line. I'm on Mac OSX btw. so I added to my .spec Source: myapp.tar.gz and %setup -q and %install rm -rf $RPM_BUILD_ROOT mkdir -p $RPM_BUILD_DIR/opt/webapps mkdir -p $RPM_BUILD_DIR/opt/myapp cp -a myapp.war $RPM_BUILD_DIR/opt/webapps cp -a Datafile1.txt $RPM_BUILD_DIR/opt/chrome cp -a Datafile2.txt $RPM_BUILD_DIR/opt/chrome –  David Williams May 31 '13 at 17:51
    
Then in the %files section %files %defattr(-,www-data,www-data,-) /opt/webapps/myapp.war /opt/myapp/Datafile1.txt /opt/myapp/Datafile2.txt –  David Williams May 31 '13 at 17:52
    
I also needed to put the tar.gz in rpmbuild/SOURCES/myapp.tar.gz and I tried putting my .spec in rpmbuild/SPECS/myapp.spec Then I ran $ rpmbuild SPECS/myapp.spec But it appears that nothing happend: $ ls rpmbuild/SRPMS/ rpmbuild/RPMS/ rpmbuild/RPMS/: rpmbuild/SRPMS/: I also dont see a BUILDROOT dir. What am I doing wrong? –  David Williams May 31 '13 at 17:56
    
Tell rpmbuild what to do via parameters, e.g. rpmbuild -ba –  ptr Jun 2 '13 at 7:36
    
You missed the "-ba" between rpmbuild and the spec file. Did you succeed since your last comment? –  ptr Jun 10 '13 at 13:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.