Subject: Re: DEINSTALL scripts for daemon packages
To: David Brownlee <abs@netbsd.org>
From: Johnny C. Lam <lamj@stat.cmu.edu>
List: tech-pkg
Date: 05/24/2001 13:08:40
David Brownlee <abs@netbsd.org> writes:
> On Thu, 24 May 2001, Johnny C. Lam wrote:
> >
> > No, you include some code in DEINSTALL like:
> >
> > 	case DEINSTALL)
> > 		# ... check to see if daemon is running ...
> > 		if is_running; then
> > 			echo "The ${PKGNAME} daemon is still running!"
> > 			exit 2;
> > 		fi
> >
> > Now if someone does 'pkg_delete foo', it'll fail if the foo daemon is
> > running because the DEINSTALL script returns a nonzero error.  But if
> > they run 'pkg_delete -f foo', it'll still print the warning message,
> > but will force the deinstallation of the package.
> >
> 	That would work, but it doesn't permit you to distinguish
> 	between 'daemon still running' and any other type of
> 	'DEINSTALL failed, you should look at this' error. I would
> 	find this particularly relevant when running a 'make update'
> 	which could be deleting a bunch of other packages prior to
> 	rebuild and reinstall.

Why would you need to distinguish between these deinstallation failure
errors?  The deinstallation will just fail, and the last lines printed
should be the most informative, as would be the case here, where you
would see:

	The foo daemon is still running!

Any recursive pkg_delete (without -f) will stop at this point and will
not have removed any files still being used on the system.

> > This is the kind of stuff we should _not_ be adding to the pkg_install
> > sources.  I mean, how do you check that the daemon is running across
> > all those differently named daemons in pkgsrc with different methods
> > of starting/stopping them?  The only plausible way to achieve this
> > kind of check is to do it on a package-by-package basis, which is done
> > be doing the check at DEINSTALL time.
> >
> 	That is the job of the rc.d scripts. If the check was performed
> 	by DEINSTALL then I would expect it to call those scripts.

That assumes all those daemon packages have nice rc.d-style scripts
and that people use them.  People also modify those scripts to perform
other tasks.  Some people copy them to /etc/rc.d under a different
name.  Nowhere in the NetBSD documentation does it claim that the
scripts in /usr/pkg/etc/rc.d must be used.  In fact, several of the
scripts give instructions to copy it over to /etc/rc.d.  How do you
ensure the correct script is called?

> > I really don't think we should be touching (3) in your list above: I
> > don't think that pkg_delete should be doing admin-type tasks like
> > turning off services for you.
> 
> 	I think the default should be 2 (though I will probably always run
> 	with 1). Whatever the decision we should provide the functionality
> 	that sushi will need to upgrade packages in such a situation.

Sushi can upgrade packages by removing them and adding new ones.  The
person using sushi should just have enough of a clue to check that the
daemon he's about to delete isn't still running.

Let me run through a scenario as a final argument against
auto-shutdown during pkg_delete:

Suppose someone takes, oh say the /usr/pkg/etc/pgsql rc.d script, and
places a modified copy of it in /etc/rc.d.  He's also modified the
actions so that on "stop", some messages are logged to disk, and an
email is sent to the man responsible since it's running a very
critical service, and no downtime can be tolerated.  Oh wait, but he's
also running a second postgresql daemon on another port that started
by /etc/rc.d/pgsql.private, which is another modified pgsql script.
Now clearly, you'd want to run the correct script to ensure that
postgresql is stopped correctly prior to deinstallation.  But which
one?  And how do you detect the second postgres daemon?

     -- Johnny C. Lam <lamj@stat.cmu.edu>
        Department of Statistics, Carnegie Mellon University
        http://www.stat.cmu.edu/~lamj/