3 Replies Latest reply on May 21, 2010 4:13 PM by riskyseven

    (SOLVED) JBAS-7674 solution for JBoss 5.1?? (Windows lock on jnp-service.url)

    riskyseven Newbie

      Hi all.  I'm currently updating a large application from JBoss4 to JBoss5.1.  I'm made it past many many issues but am now stuck.

       

      https://jira.jboss.org/browse/JBAS-7674?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

       

      JBAS-7674 pretty much describes my issue.  I need to use JBoss5.1, and can't migrate to JBoss6 at this time.

       

      My upgrade work is being done in Cygwin, to be deployed to Solaris at a later date.  In a nutshell, if a running server is stopped w/ a 'kill <pid>' command, there is a lock in Windows on <server>/data/jnp-service.url.  The server process is successfully killed off, and this lock is owned by the Windows system Explorer process....can't really kill that one.  If I try to start the server back up, everything blows sky high, root cause being that file permissions on this file (partial dump below if interested).  Using Sysinternal Process Explorer (love this utility!), I can pinpoint the lock on the Explorer process, and can manually release the lock w/ no ill effects.  After this release, I can restart the server successfully.  This use case can be reproduced using the standard <jboss>/bin/run.sh server.

       

      Any ideas on how I can get past this?  If there is a scripting solution that will work within Cywin/UNIX, this would be ideal....I just don't know how to do this.  Another thought was to recompile JBoss5.1 w/ the JBoss6 MR2 fix, but I'm not fond of running w/ a custom rolled JBoss5.1 and would like to avoid it if at all possible...haven't researched if this is even possible.

       

      Has anyone worked around this?  Any help would be greatly appreciated.  Thanks.

       

       

       

      14:35:16,357 INFO  [WebService] Using RMI server codebase: http://127.0.0.1:8083/^M
      14:35:16,732 ERROR [AbstractKernelController] Error installing to Start: name=jboss:service=NamingProviderURLWriter stat
      e=Create mode=Manual requiredState=Installed^M
      java.io.IOException: Access is denied^M
              at java.io.WinNTFileSystem.createFileExclusively(Native Method)^M
              at java.io.File.createNewFile(File.java:883)^M
              at org.jboss.naming.NamingProviderURLWriter.start(NamingProviderURLWriter.java:117)^M
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)^M
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)^M
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)^M
              at java.lang.reflect.Method.invoke(Method.java:597)^M
              at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157)^M
              at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96)^M
              at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:138)^M
              at org.jboss.mx.server.Invocation.invoke(Invocation.java:90)^M
              at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:140)^M
              at org.jboss.mx.server.Invocation.invoke(Invocation.java:90)^M
              at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)^M
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)^M
              at org.jboss.system.microcontainer.ServiceProxy.invoke(ServiceProxy.java:206)^M
              at $Proxy38.start(Unknown Source)^M
              at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:42)^M
              at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:37)^M

        • 1. Re: JBAS-7674 solution for JBoss 5.1?? (Windows lock on jnp-service.url)
          jaikiran pai Master

          The only way I can think of is, that you apply the patch against JBoss AS 5.1.0.

          • 2. Re: JBAS-7674 solution for JBoss 5.1?? (Windows lock on jnp-service.url)
            riskyseven Newbie

            Thanks, Jaikiran.  I think I have successfully back-patched NamingProviderURLWriter.java rev. 100316 to the version in Jboss 5.1.0 GA.  After further testing passes, I will post the code.  Maybe someone associated w/ the project can integrate it in to the JBoss 5.1 branch...or at least it will help some random Googler.

            • 3. Re: JBAS-7674 solution for JBoss 5.1?? (Windows lock on jnp-service.url)
              riskyseven Newbie

              This code fixed my problem.  It is simply a back-patch of the JBoss 6 solution.

               

              /*
              * JBoss, Home of Professional Open Source.
              * Copyright 2008, Red Hat Middleware LLC, and individual contributors
              * as indicated by the @author tags. See the copyright.txt file in the
              * distribution for a full listing of individual contributors.
              *
              * This is free software; you can redistribute it and/or modify it
              * under the terms of the GNU Lesser General Public License as
              * published by the Free Software Foundation; either version 2.1 of
              * the License, or (at your option) any later version.
              *
              * This software is distributed in the hope that it will be useful,
              * but WITHOUT ANY WARRANTY; without even the implied warranty of
              * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
              * Lesser General Public License for more details.
              *
              * You should have received a copy of the GNU Lesser General Public
              * License along with this software; if not, write to the Free
              * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
              * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
              */

               

              package org.jboss.naming;

               

              import java.io.BufferedReader;
              import java.io.File;
              import java.io.FileReader;
              import java.io.IOException;
              import java.io.PrintWriter;
              import java.net.Inet6Address;
              import java.net.InetAddress;
              import java.net.NetworkInterface;
              import java.net.SocketException;
              import java.net.URI;
              import java.util.Enumeration;

               

              import org.jboss.bootstrap.spi.Server;
              import org.jboss.logging.Logger;

               

              /**
              *
              *
              * @author Brian Stansberry
              * Mike Jackson - 2010/05/19 - Patched JBoss6 MR2 file for JBoss5.1
              * https://jira.jboss.org/browse/JBAS-7674?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
              */
              public class NamingProviderURLWriter
              {
                 public static final String DEFAULT_PERSIST_FILE_NAME = "jnp-service.url";
                
                 private static final Logger log = Logger.getLogger(NamingProviderURLWriter.class);
                
                 private String bootstrapUrl;
                 private String bindAddress;
                 private int port;
                 private Server  server;
                 private URI outputDir;
                 private String filename = DEFAULT_PERSIST_FILE_NAME;

               

                 public URI getOutputDirURI()
                 {
                    return outputDir;
                 }

               

                 public void setOutputDirURL(URI dir)
                 {
                    this.outputDir = dir;
                 }

               

                 public String getOutputFileName()
                 {
                    return filename == null ? DEFAULT_PERSIST_FILE_NAME : filename;
                 }

               

                 public void setOutputFileName(String name)
                 {
                    this.filename = name;
                 }

               

                 public void setServer(Server server)
                 {
                    this.server = server;
                 }

               

                 public String getBootstrapURL()
                 {
                    return bootstrapUrl;
                 }
                
                 public void setBootstrapURL(String url)
                 {
                    this.bootstrapUrl = url;     
                 }

               

                 public String getBootstrapAddress()
                 {
                    return bindAddress;
                 }

               

                 public void setBootstrapAddress(String bindAddress)
                 {
                    this.bindAddress = bindAddress;
                 }

               

                 public int getBootstrapPort()
                 {
                    return port;
                 }

               

                 public void setBootstrapPort(int port)
                 {
                    this.port = port;
                 }

               

                 public void start() throws Exception
                 {
                    establishBootStrapURL();
                   
                    if (bootstrapUrl != null)
                    {
                       File base = null;
                       if (outputDir == null)
                       {
                          if (server != null)
                          {
                             base =  new File(server.getConfig().getServerDataDir().toURI());
                             outputDir = base.toURI();
                          }
                       }
                       else
                       {
                          base = new File(outputDir);
                       }
                      
                       if (base != null)
                       {
                          base.mkdirs();
                         
                          File file = new File(base, getOutputFileName());
                          if (file.exists())
                          {
                             file.delete();
                          }
                          PrintWriter writer = null;
                          try
                          {              
                             if (log.isTraceEnabled())
                             {
                                log.trace("Creating file " + file);
                             }
                             file.createNewFile();
                             file.deleteOnExit();
                            
                             writer = new PrintWriter(file);
                             writer.println(bootstrapUrl);
                             writer.flush();
                          }
                          catch (Exception e)
                          {
                             handleOutputFileCreationException(file.toURI(), e);
                          }
                          finally
                          {
                             if (writer != null)
                             {
                                writer.close();
                             }
                          }
                       }
                       else
                       {
                          log.warn("No directory specified for " + getOutputFileName() +
                                " cannot write the naming service url. Please configure either " +
                                "the 'server' property or the 'outputDir' property.");
                       }
                    }
                    else
                    {
                       log.debug("No URLs to write");
                    }
                 }

               

                 /** JBAS-7674 Try to intelligently deal with case where Windows has the file locked */
                 private void handleOutputFileCreationException(URI outputFile, Exception e)
                 {
                    boolean handled = false;
                    FileReader fr = null;
                    try
                    {
                       File f = new File(outputFile);
                       if (f.exists())
                       {
                          fr = new FileReader(f);
                          String existing = new BufferedReader(fr).readLine();
                          if (existing != null && this.bootstrapUrl.equals(existing.trim()))
                          {
                             log.info("Experienced a problem (" + e +
                                      ") updating the naming service URL file " + outputFile +
                                      " but the current contents are correct.");
                          }
                          else
                          {
                             log.error("Cannot update naming service URL file " + outputFile, e);
                          }
                          handled = true;
                       }
                    }
                    catch (Exception ignored)
                    {
                       ;
                    }
                    finally
                    {
                       if (fr != null)
                       {
                          try
                          {
                             fr.close();
                          }
                          catch (Exception ignored) {}
                       }
                    }
                   
                    if (!handled)
                    {
                       log.error("Cannot create a naming service URL file at " + outputFile, e);
                    }
                   
                 }

               

                 public void stop() throws Exception
                 {
                    if (outputDir != null)
                    {
                       String outputFile = "";
                       try
                       {
                          File f = new File(new File(outputDir), getOutputFileName());
                          outputFile = f.getAbsolutePath();
                          f.delete();
                       }
                       catch (Exception e)
                       {
                          log.warn("Failed to delete JNP URL file " + outputFile + " due to " + e);
                       }
                    }
                 }

               

                 protected void establishBootStrapURL() throws IOException
                 {
                    if (getBootstrapURL() == null && getBootstrapAddress() != null)
                    {
                       InetAddress addr = InetAddress.getByName(getBootstrapAddress());
                       if (addr.isAnyLocalAddress())
                       {
                          addr = findLoopbackAddress();
                          if (addr == null)
                          {
                             addr = InetAddress.getLocalHost();
                          }
                       }
                      
                       // Build the bootstrap URL
                       StringBuilder sb = new StringBuilder("jnp://");
                       if (addr instanceof Inet6Address)
                       {
                          sb.append('[');
                          sb.append(addr.getHostAddress());
                          sb.append(']');
                       }
                       else
                       {
                          sb.append(addr.getHostAddress());
                       }
                       sb.append(':');
                       sb.append(getBootstrapPort());
                       setBootstrapURL(sb.toString());
                    }
                 }

               

                 private static InetAddress findLoopbackAddress() throws SocketException
                 {
                    Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();
                    while (ifaces.hasMoreElements())
                    {
                       NetworkInterface iface = ifaces.nextElement();
                       Enumeration<InetAddress> addrs = iface.getInetAddresses();
                       while (addrs.hasMoreElements())
                       {
                          InetAddress addr = addrs.nextElement();
                          if (addr.isLoopbackAddress())
                          {
                             return addr;
                          }
                       }
                    }
                    return null;
                 }

               

              }