NOTE: The information in this article is provided without warranty of any kind.  This method has been successfully tested, however, there may be cases where it doesn't work.  You'll need to know a little about shell scripting, and you'll need to use your own judgement to modify these guidelines as necessary, since every case will be slightly different.  That having been said, on to the details....

 

 

 

The package management system on modern Linux distributions is so advanced, that it usually works so seamlessly, there is nothing to think about.  Nothing even remotely like rpm or dpkg-deb exists in the Windows world.

 

Occasionally, however, a corrupted file or package will cause problems, which can be difficult to troubleshoot, due to the advanced nature of these package managers.

 

A recent Debian Linux server upgrade from version 4.0 to version 5.0 caused a few problems, due to this situation.

 

In this case, the package (ippl) ran the script to stop the daemon process (called a system service in Windows) running, and the script failed, resulting in errors like the following:

 

root@server:# apt-get remove --purge ippl
(Reading database ... 121400 files and directories currently installed.)
Removing ippl ...
* Stopping ippl start-stop-daemon: warning: init.d: initscript ippl action "stop" failed.
dpkg: error processing ippl (--remove):
subprocess pre-removal script returned error exit status 1
* Starting ippl
subprocess post-installation script returned error exit status 1
Errors were encountered while processing:
ippl

root@server:#

 

Checking the initscript revealed nothing amiss, and even modifying it to always return a successful result code didn't fix the problem.

Running ps -A | grep ippl showed that the process was not running, so it could safely be removed, as long as the error could be worked around.

 

On Debian-based distributions (package files end in .deb) there is a pre-removal script for each package.  This script is run before the uninstallation of any software package, to do things like, clean up temporary files belonging to the package, or shut down daemons before they are uninstalled.

 

It was this shut down process for the ippl daemon that was failing, even though it wasn't running in the first place.

 

On Debian, these scripts are stored in:

 

/var/lib/dpkg/info/

 

There are several files for each package, in the case of ippl, there are these files:

 

root@server:/var/lib/dpkg/info# ls ippl*
ippl.conffiles ippl.list ippl.md5sums ippl.postinst ippl.postrm ippl.preinst ippl.prerm
root@server:/var/lib/dpkg/info#

 

The filenames obviously start with the name of the package, and the extension determines what the file is used for.

 

ippl.conffiles contains all the configuration files the package uses that are stored in the /etc/ configuration directory.

ippl.list contains a list of all files and directories in the package.

ippl.md5sums contains the md5 hashes for all files, to determine if there is any file corruption.

 

These files are unimportant for this discussion, but it's still nice to know what they're for.

 

The other files are all scripts run when removing or installing packages.  The extensions are fairly self-explanatory, but I'll list them here:

 

ippl.preinst is run before installation of the package.  Usually configuration options are set using prompts in this script.

ippl.postinst is run after installation of the package.  This is where daemons are started for packages that contain them.

ippl.prerm is run before removal of the package.  This is used for removal options, for example, remove just the program, or data also.  It is also used for shutting down daemons when needed.

ippl.postrm is run after removal of the package.  Any final cleanup will be done in this script.

 

In this case, the ippl.prerm script was either throwing the error, or running another command that threw the error preventing removal of the package.

This script is fairly simple for this package, consisting of the following code:

 

#!/bin/sh
set -e
# Automatically added by dh_installinit
if [ -x "/etc/init.d/ippl" ]; then
if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
invoke-rc.d ippl stop || exit $?
else
/etc/init.d/ippl stop || exit $?
fi
fi
# End automatically added section

 

This essentially makes sure the startup/shutdown initscript for the daemon exists, then determines if invoke-rc.d exists.  If it does, it uses this method to shut down the daemon.  If not, it uses the legacy initscript method.

 

In a case this simple, it really doesn't matter what method is being used, as the script is simple enough to modify for both options.

 

Simply comment out the two shutdown lines, and add another line that does basically nothing to replace each, otherwise the shell will throw an error due to an if statement containing no instructions:

 

#!/bin/sh
set -e
# Automatically added by dh_installinit
if [ -x "/etc/init.d/ippl" ]; then
if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
#### invoke-rc.d ippl stop || exit $?
echo "not shutting down"
else
#### /etc/init.d/ippl stop || exit $?
echo "still not shutting down"
fi
fi
# End automatically added section

 

These changes will make the pre-removal script do basically nothing, other than print a message.  Shutting down the daemon will not happen, but since it wasn't running anyway, this is irrelevant.  If your daemon is still running, try shutting it down with the initscript in /etc/init.d, or, failing this, use the kill command to shut it down.

 

After these changes were made, the ippl package from Debian version 4.0 uninstalled with no errors, allowing the version 5.0 package to be installed.