multi-named instance exist?

Doug Barton dougb at dougbarton.us
Thu Mar 26 06:02:48 UTC 2009


dev_null at zoho.com wrote:
> 
> 
>  > If named is invoked successfully on startup, then the contents of the 
>  > PID file will be overwritten with the new PID value. 
>  >  
>  > If named *isn't* invoked successfully on startup, then that's a separate 
>  > error condition that should be detected and dealt with, within the whole 
>  > startup subsystem. 
>  >  
>  > The problems with using "ps" to find the named process include: 
>  > -- you can get false matches if you don't tailor your string matching 
>  > _just_right_, 
>  > -- unexpectedly "missed" matches if the command-line arguments change, 
>  > even a little bit (e.g. if someone bypasses the wrapper script on an 
>  > emergency basis to start the process manually, with the arguments given 
>  > perhaps in a different order), and 
>  > -- since "ps" operates on a constantly-changing data source, it can 
>  > "miss" legitimate processes in the process table. I've seen that happen 
>  > many many times with "ps" on Solaris, not sure if Linux or other flavors 
>  > of Unix have some sort of concurrency-control mechanism to prevent that 
>  > phenomenon. 
>  >  
>  
> 
> I agree all your opitions on ps's drawbacks.
> what I said is, kill -0 $PID will return true even the process who owns $PID isn't named.
> 
> for example, named.pid wasn't removed after a system shutdown, the value in it is 1234.
> after system startup, another process is launched and owns that process id of 1234.

Boys boys boys .... there is no need to fight, you're both right. :)

NAMED_PID=/path/to/pid

if [ -e "$NAMED_PID" ]; then
	if ps -p `cat $NAMED_PID` | grep named; then
		# named is already running, do what's appropriate
	else
		# pid file is bogus, remove it and start named
		unlink $NAMED_PID
		<start named>
	fi
else
	if ps -U nobody | grep named; then
		# named is running without a pid file, oops
		<do something useful>
	else
		if ps -ax | grep [n]amed; then
			# something is probably really wrong here
			# probably want to stop and look first
		else
			<start named>
		fi
	fi
fi


I agree with Kevin that ps on Solaris has "issues," although I've
never had similar problems on FreeBSD I still prefer to try and cover
all the bases. Limiting the number of processes that you examine with
ps by looking only at those with user nobody helps limit your chances
of false positives, although it doesn't cover someone typing 'named'
as root.

Of course on FreeBSD the /etc/rc.d/named script already handles all of
this and much more for you. :)


Doug



More information about the bind-users mailing list