You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Norbet Reilly <nr...@gmail.com> on 2006/06/05 09:26:54 UTC

Re: Detecting LDAP Port busy at start-up (Repost)

here's the repost...
====================

I'm not sure whether to direct this question to the ApachedDS dev
list, or the MINA one...

I use an ApacheDS deployment with a custom partition that replaces an
existing directory installation. I want to detect the situation where
the other directory is already listening on the configured port, at
the time A-DS is started, and abort or at least log a very prominent
message.

With my current limited understanding I am leaning toward adding a
configuration setting to
org.apache.directory.server.configuration.MutableServerStartupConfiguration
(say "abortIfLdapPortInUse=true") and using it in
org.apache.directory.server.jndi.ServerContextFactory.startLDAP0() to
drive an optional check for "already in use" using
ServerSocket.bind().

Similar semantics may make sense for the other protocols that A-DS
supports, in which case it may be a case of a single
"abortIfAnyPortInUse" config item, or perhaps one per protocol.

Anyone have any thoughts or alternative implementation suggestions ?

Thanks

Re: Detecting LDAP Port busy at start-up (Repost)

Posted by Norbet Reilly <nr...@gmail.com>.
The usecase I have in mind is trying to detect if there is already an
OpenLDAP directory (C/C++) listening to the same port as A-DS, at the
time that A-DS is started.

In this situtation I have found that the OpenLDAP directory gets all
the traffic but there is no way to draw the user's attention to the
problem.

My understanding is that ServerSocket.bind() would detect the
situation, but because of the current implementation (based on nio)
the check is simply not being performed. I had in mind the Tomcat
behaviour, where it won't start up when it's port is busy (or is it
just the easier case of simply detecting when another Tomcat is using
the same port ?). I thought there was stuff in socket support to tell
if a particular socket was already being listened to, but then it's
been a long time since I last visited this low in the comms stack...

Quoting from http://www.cafeaulait.org/course/week12/26.html  (which
is admittedly old) which I found in a google :
"When you create a ServerSocket object, it attempts to bind to the
port on the local host given by the port argument. If another server
socket is already listening to the port, then a
java.net.BindException, a subclass of java.io.IOException, is thrown.
No more than one process or thread can listen to a particular port at
a time. This includes non-Java processes or threads. For example, if
there's already an HTTP server running on port 80, you won't be able
to bind to port 80."

The rest of my post was thinking out load about how to allow flexible
configuration of the "port busy" check, assuming that this check would
not required in all deployment situations (although it seems to me to
be the more sensible default).

Re: Detecting LDAP Port busy at start-up (Repost)

Posted by Alex Karasulu <ao...@bellsouth.net>.
Norbet Reilly wrote:

> here's the repost...
> ====================
>
> I'm not sure whether to direct this question to the ApachedDS dev
> list, or the MINA one...
>
> I use an ApacheDS deployment with a custom partition that replaces an
> existing directory installation. I want to detect the situation where
> the other directory is already listening on the configured port, at
> the time A-DS is started, and abort or at least log a very prominent
> message.

Hmm this is pretty hard to do right now.  The best way to test this is
to try to bind to the port with a little connection test.

BTW I'm presuming that the two installations are running in separate
JVMs.  Am I correct here or did I miss something?

Alex

>
> With my current limited understanding I am leaning toward adding a
> configuration setting to
> org.apache.directory.server.configuration.MutableServerStartupConfiguration
>
> (say "abortIfLdapPortInUse=true") and using it in
> org.apache.directory.server.jndi.ServerContextFactory.startLDAP0() to
> drive an optional check for "already in use" using
> ServerSocket.bind().
>
Sounds like you want to test if the server has bound in the same JVM
instance.  Is this the case?

> Similar semantics may make sense for the other protocols that A-DS
> supports, in which case it may be a case of a single
> "abortIfAnyPortInUse" csonfig item, or perhaps one per protocol.

Yeah it might for sure.   I do want to understand your use case a bit
better.   Could you elaborate some more with greater detail?

Thanks,
Alex