After trying to delete apache and tomcat, and now trying to reinstall apache 2, I am missing the init.d/apache2 file to start/stop my server.
I am not sure if the new install actualy worked, and my apt-get purge apache2 didn’t remove everything in the first place!
How can I get the init.d/apache2 file to test if server starts / is installed properly (I had removed files and directories manually)?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
(I’m following up on Caleb’s answer, though most of the relevant information will be in the comments already. I figure a summary might be more convenient than having to look through the comments.)
So, the issue, as described in Caleb’s post, was that Alexander deleted (or possibly modified)/etc/init.d/apache2 and wanted to get it back. This file is in apache-2.2-common. The obvious apt-get install --reinstall apache2.2-common doesn’t restore the file, though. The reason for this, per Debian policy, is that config files are not touched by the system once they have altered, unless explicitly asked by the user. See Debian Policy on config file handling: Section 10.7.3. Quote:
Configuration file handling must conform to the following behavior:
- local changes must be preserved during
a package upgrade, and- configuration files must be
preserved
when the package is removed, and only
deleted when the package is purged.
Packages additions and removals are handled by dpkg. dpkg distinguishes two cases here, when the file is modified, and when it has been completely removed. See the section in the options section starting with --force-things in the dpkg man page. (Linking to Ubuntu’s dpkg 1.16 page, because I could not find the Debian squeeze man pages online. If you have a pointer, please comment.)
So for the two situations
-
If you want conf files that have
been removed to be replaced by
reinstallation, you need to pass the
--force-confmissoption to dpkg. -
If you want conf files that have
been altered, but not removed, to be
replaced by their default version on
installation, you need to pass both
the--force-confnewand
--force-confaskoptions to dpkg.
As the man page explains, –force-confnew
by itself will only replace the modified
conf file with the default in cases when
the default is newer than the originally
installed default, i.e. on an upgrade.
If we are invoking dpkg via apt, we need to pass these options to apt. This is done as follows for the two cases above :
apt-get -o Dpkg::Options::="--force-confmiss" install --reinstall apache2.2-common apt-get -o Dpkg::Options::="--force-confnew" -o Dpkg::Options::="--force-confask" install --reinstall apache2.2-common
I could not find any documentation for Dpkg::Options. I found it by Googling. If you know of any, please comment.
Comments:
-
I think if you are faced with a
situation where you have messed up a
config file and want to back, it is
safer to rename it, and then use
--force-confmissrather than
asking for all your local
modifications to be replaced by the
default per--force-confnew, which
is in general not what you want. -
If working with config files, always
keep them under version control.
This would make the issues of messed
up config files moot. I use and
recommend
mercurial.
In this case (and probably any case
:-)), you are better off in this
context using distributed version
control than a centralized version
control system like
subversion.
A good program for doing this is
etckeeper. -
It is also worth mentioning, and
might have contributed to the
confusion here, that with apt in
squeeze,apache2.2-commondoes
not uninstall cleanly, because of
apt bug
621720,
which coincidentally covers the
case ofapache2.2-commonremoval.
Per the bug report you will need to useapt-get remove apache2.2-common -o pkgProblemResolver::FixByInstall=0`
(verified by me).
-
See Everything you need to know
about conffiles: configuration files
managed by
dpkg
for a discussion of dpkg’s config
file handling by Raphaël
Hertzog,
one of dpkg’s developers. He
mentions that--force-confaskis
new in Squeeze. He also mentions thatdpkg --status apache2.2-common
gives the list of conffiles,
along with other information. or justdpkg-query --showformat='${Conffiles}n' --show apache2.2-commonif you only want that information.
Thanks to David Kalnischkies and Raphaël Hertzog for answering my questions about this (and telling me I was posting to the wrong mailing list). I think the Debian documentation in this context could be improved, and specifically, the dpkg man page could do with additional usage examples. I encourage people here (who are obviously willing to help out) to also take time to contribute documentation patches to free software projects like Debian. It is valuable work and there are not enough people doing it.
Method 2
Try using apt-get install --reinstall apache2 to force the apt-get system to install again even though the package exists and overwrite current files — even the ones it thinks are already there.
By manually deleting things from the system you undoubtedly have the package manager confused about what needs doing where. You usually want to stick to using the tools provided unless you understand what you are effecting by manually fiddling.
As an extra note, you don’t usually need to mess with the files in /etc/init.d yourself. There is a tool that takes care of running those scripts for you. For example to restart apache you could run service apache2 restart.
Edited based on information found in comments
The init script is part of a sub-package. Installing a package for the first time will install it’s dependencies, but uninstalling it will just uninstall the package, not it’s dependencies. The init script that you manually removed belongs to the apache2.2-common package with was a dependency of the main apache2 package name. Removing apache2 even with --purge would have no effect on the init script because it’s part of a different package. To get it back run apt-get install --reinstall apache2.2-common.
Edit2
Apparently Debian is wacky. I replicated the problem on a test system and was unable to get the init script back with the package manager. I found several other people with the same problem out on the web, and it looks like the solution is to manually download the package, extract it, and rip the file out like this:
cd /tmp aptitude download apache2.2-common dpkg --extract apache2.2-common_*.deb apache2.2-common sudo cp apache2.2-common/etc/init.d/apache2 /etc/init.d
Edit3
Thanks to investigation done by Faheem Mitha and discussion on the comments below, a full answer to this question has worked out. Read Faheem’s answer for full details. For humor value, here are the cliff notes:
The short version is that init scripts are considered conf files, and apt-get is too polite to touch conf files that have been user-modified in any way, even to restore deleted on reinstall after a uninstall. Before you say “duh of course”, check out the gymnastics you have to do. I quote:
After asking the dpkg list (and being told off for it) + further fiddling, the following works. Be careful with this. It will replace all your modified config files with the version from the package.
apt-get -o Dpkg::Options::="--force-confnew" -o Dpkg::Options::="--force-confask" install --reinstall apache2.2-common. I don’t know why you needed me to tell you this. It’s the first thing you should have thought of. 🙂 – Faheem Mitha
Method 3
I had this exact same problem on a Debian system. It affected both apache and nginx.
All solutions here did not work for me; purging, reinstalling, downloading and manual install and Dpkg::Options didn’t work.
It turns out one of the dependencies creates the config files needed to start and stop the services. You simply remove all dependencies and do a fresh reinstall.
I found the solution here: http://dancingpenguinsoflight.com/2009/02/how-to-completely-reset-an-apache-instance-in-ubuntu/
APACHE_PKGS=`sudo dpkg --get-selections | grep apache | cut -f 1` # Make sure things are sane: echo $APACHE_PKGS # Example output: apache2 apache2-mpm-prefork apache2-utils apache2.2-common # libapache2-mod-php5 libapache2-mod-python libapache2-svn # Likely if you have a Python application: # libapache2-mod-python libapache2-mod-python-doc libapache2-mod-wsgi # Or if you roll with the PHP: # libapache2-mod-php5 sudo apt-get remove --purge $APACHE_PKGS
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0