[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Service stopping in prerm considered harmful

Pierre THIERRY schrieb am Sunday, den 23. March 2008:

> For the nth time, I have a package that dpkg is unable to remove because
> it tries to stop a service that either is already stopped (I didn't want
> it) or couldn't start at all. In the former case, the fix seems simple:
> start the service and remove the package. But sometimes starting the
> service may have undesirable outcomes on the system, or the stop action
> will fail in some way.
> In either case, when you can't get a successful stop action for the
> service init.d script, the package is impossible to remove without human
> action, and not a simple one, because you need to be able to hack the
> maintainer scripts or the init.d script.
> Shouldn't the maintainer script actually ensure that the service is not
> running, instead of just triggering the stop action and checking its
> exit code? Something like (it's pseudo-code, because the status action
> of init.d scripts prints text, it doesn't seem to give machine-friendly
> data):
> ------------------------------------------------------------------------
> # if it's running, stop it
> if(status(service) == running) {
> 	stop(service);
> }
> # if now it's still running, something's wrong
> if(status(service) == running) {
> 	exit 1;
> }
> # proceed...
> ------------------------------------------------------------------------
There is a small trick with dh_installinit that can be used. dh_installinit
supports an errorhandler. If called like: 

dh_installinit -i --error-handler=init_failed --init-script=amavis -- defaults 19 21

it generates the following debhelper code for prerm and postinst:
invoke-rc.d amavis stop || init_failed 

All you need then is a small function like in your postinst: 

init_failed () 
	echo "WARNING: Starting amavisd-new failed. Please check your

This works fine for me and removes the annoying default behaviour of


Reply to: