Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have this spec file that will install numerous rpm packages such as apache, mysql, etc. I'm new to building rpms and I did looked at the Fedora documentation but I did not find the answer to my question.

How do I add commands in my spec file so that if I do a:

rpm -e 
yum erase

it will stop services that wasn't stopped during yum erase/rpm-e?


share|improve this question

It may not be relevant to this case, but remember that if you will upgrade your RPM, rpm will install the new version and then remove the old one, so after upgrade the services will be down. To be on the safe side, do:

if [[ $1 -eq 0 ]]
    service https stop
    # or what ever you want
share|improve this answer

There is a section in spec file preun which runs before package is uninstalled:

service https stop
# or what ever you want
share|improve this answer

Your Answer


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.