understanding an rpm spec file

I have a following spec file . Please help me understand its different components :
Version: 0.4.3
Release: 1
License: Commercial
Group: System Environment/Daemons
Source0: %{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
BuildArch: x86_64
BuildRequires: libevent-devel
Requires: libevent
Requires(pre): shadow-utils
Requires(post): chkconfig, initscripts
Requires(preun): chkconfig, initscripts


%setup -q




%doc README.md

%define groupname %{name}
%define username %{name}

getent group %{groupname} >/dev/null || groupadd -r %{groupname}
getent passwd %{username} >/dev/null || useradd -r -g %{groupname} -s /sbin/nologin %{username}
install -d /var/log/%{name} -o %{username} -g %{groupname} -m 750
exit 0

/sbin/chkconfig --add uecho

if [ "$1" -eq "0" ] ; then
    /sbin/service uecho stop >/dev/null 2>&1
    /sbin/chkconfig --del uecho

- Create log path with appropriate permissions during installation.
- Add logrotate script.

- Initial build.

Open in new window

Any pointers to some of the above thing would be great. Also please share any tutorial or link for the same.
Some particular things i want to understand is the code part :
getent group %{groupname} >/dev/null || groupadd -r %{groupname}
getent passwd %{username} >/dev/null || useradd -r -g %{groupname} -s /sbin/nologin %{username}
install -d /var/log/%{name} -o %{username} -g %{groupname} -m 750
exit 0

Open in new window

I think this is what is performed prior to installation of the rpm.
what is this doing. i dont understand the getent part.
why a group is added and user is added ?
Rohit BajajAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

joolsSenior Systems AdministratorCommented:
most of the sections are self explanatory but the %pre and %post sections are executed prior to and after installation.

The getent is a linux command for this; http://man7.org/linux/man-pages/man1/getent.1.html but you can obviously have anything in the %pre and %post as these are basically scripts.

There is more info here https://fedoraproject.org/wiki/How_to_create_an_RPM_package
Rohit BajajAuthor Commented:
when does %files and %post gets executed.
I wrote a spec file and it looks like the file i have specified in the %files is copied after the %post gets executed.
joolsSenior Systems AdministratorCommented:
this gives more information about scriptlets https://fedoraproject.org/wiki/Packaging:ScriptletSnippets?rd=Packaging/ScriptletSnippets.

Are you able to share your spec file?
Rohit BajajAuthor Commented:
I guess some problem with my scrip file only.

I am using the following post script :
ps -ef | grep '[j]etty' >/dev/null
if [ $? -ne 0 ]; then
  nohup service jetty start &
  service jetty stop &;
  nohup service jetty start &

Open in new window

Do you see any problem with it seems like the two statements  (else )are not getting executed...
The second statement needs to run only after the first statement has finished
probably thats what is causing the issue.
joolsSenior Systems AdministratorCommented:
best check this out, https://fedoraproject.org/wiki/Packaging:SysVInitScript?rd=Packaging/SysVInitScript

I only scanned the article but look for postun, there is also a note about chroot environments.

I have to admit I didnt know that myself and would have probably tried starting the script like you have above.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.