You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by Norman Maurer <nm...@byteaction.de> on 2006/07/19 10:05:42 UTC

phoenix and commons daemon (jsvc) not seems to work

Hi guys,

i tried to get phoenix (james) to work with commons daemon. And by now i
really have no  idea why it no work and whats the problem. This just
drives my crazy.. So maybe a other commiter has a idee .. or maybe Peter
Royal ( he worked on avalon if im not wrong).. 

 I created a jar called phoenix-daemon-loader.jar which contains just
one class which is needed for jsvc to invoke phoenix. The class will be
posted on the end of the email.. I compiles jsvc and move it to the bin
path of james. I also moved the commons-daemon.jar and
phoenix-daemon-loader.jar in the dir.

Then i tried to start phoenix (james) with jsvc by calling:

root@debbox:/tmp/james-3.0-dev/bin# ./jsvc
-Djava.ext.dirs=/tmp/james-3.0-dev/lib:/tmp/james-3.0-dev/tools/lib
-Djava.security.manager
-Djava.security.policy=jar:file:/tmp/james-3.0-dev/bin/phoenix-loader.jar\!/META-INF/java.policy  -Dphoenix.home=/tmp/james-3.0-dev -Djava.io.tmpdir=/tmp/james-3.0-dev/temp -cp commons-daemon.jar:phoenix-daemon-loader.jar:phoenix-loader.jar  -wait 30 -nodetach -errfile error.log org.apache.avalon.phoenix.launcher.CommonsDaemonLauncher

This should be right from the docs of commons daemon. But phoenix get
not started. See error.log:

org.apache.avalon.phoenix.containerkit.lifecycle.LifecycleException:
Component named "nntpserver" failed to pass through the
 Starting stage. (Reason: java.net.BindException: Permission denied).
        at
org.apache.avalon.phoenix.containerkit.lifecycle.LifecycleHelper.fail(LifecycleHelper.java:354)
        at
org.apache.avalon.phoenix.containerkit.lifecycle.LifecycleHelper.startup(LifecycleHelper.java:226)
        at
org.apache.avalon.phoenix.components.application.DefaultApplication.startup(DefaultApplication.java:530)
        at
org.apache.avalon.phoenix.components.application.DefaultApplication.doRunPhase(DefaultApplication.java:478)
        at
org.apache.avalon.phoenix.components.application.DefaultApplication.runPhase(DefaultApplication.java:409)
        at
org.apache.avalon.phoenix.components.application.DefaultApplication.start(DefaultApplication.java:180)
        at
org.apache.avalon.framework.container.ContainerUtil.start(ContainerUtil.java:260)
        at
org.apache.avalon.phoenix.components.kernel.DefaultKernel.startup(DefaultKernel.java:295)
        at
org.apache.avalon.phoenix.components.kernel.DefaultKernel.addApplication(DefaultKernel.java:376)
        at
org.apache.avalon.phoenix.components.deployer.DefaultDeployer.deploy(DefaultDeployer.java:357)
        at
org.apache.avalon.phoenix.components.embeddor.DefaultEmbeddor.deployFile(DefaultEmbeddor.java:542)
        at
org.apache.avalon.phoenix.components.embeddor.DefaultEmbeddor.deployFile(DefaultEmbeddor.java:535)
        at
org.apache.avalon.phoenix.components.embeddor.DefaultEmbeddor.deployFiles(DefaultEmbeddor.java:520)
        at
org.apache.avalon.phoenix.components.embeddor.DefaultEmbeddor.deployDefaultApplications(DefaultEmbeddor.java:509)
        at
org.apache.avalon.phoenix.components.embeddor.DefaultEmbeddor.execute(DefaultEmbeddor.java:268)
        at
org.apache.avalon.phoenix.frontends.CLIMain.run(CLIMain.java:198)
        at java.lang.Thread.run(Thread.java:595)
Caused by: java.net.BindException: Permission denied
        at java.net.PlainSocketImpl.socketBind(Native Method)
        at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:359)
        at java.net.ServerSocket.bind(ServerSocket.java:319)
        at java.net.ServerSocket.<init>(ServerSocket.java:185)
        at
org.apache.avalon.cornerstone.blocks.sockets.DefaultServerSocketFactory.createServerSocket(DefaultServerSocketFac
tory.java:74)
        at
org.apache.james.core.AbstractJamesService.initializeServerSocket(AbstractJamesService.java:376)
        at
org.apache.james.core.AbstractJamesService.initialize(AbstractJamesService.java:352)
        at
org.apache.avalon.framework.container.ContainerUtil.initialize(ContainerUtil.java:244)
        at
org.apache.avalon.phoenix.containerkit.lifecycle.LifecycleHelper.startup(LifecycleHelper.java:200)
        ... 15 more


But why ? i start it as root .. I also tried to use ports higher then
1024. Same problem.. Any idea what i missed ?

BTW, i wrote a sample application which just bind ports and get started
with jsvc. No problems there. So the porblems seems to be in phoenix..

bye
Norman

CommonsDaemonLauncher.class:
package org.apache.avalon.phoenix.launcher;

import org.apache.avalon.phoenix.launcher.Main;
import org.apache.commons.daemon.Daemon;
import org.apache.commons.daemon.DaemonContext;
import org.apache.commons.daemon.DaemonController;

import java.util.Hashtable;
import java.util.Observable;
import java.util.Observer;

/**
 * Phoenix launcher using Commons daemon.
 */
public class CommonsDaemonLauncher implements Daemon, Observer
{

    private DaemonContext    m_context;

    private DaemonController m_controller;

    private String[]         m_args;

    public void init(final DaemonContext daemonContext) throws Exception
    {
        m_context = daemonContext;
        m_controller = m_context.getController();
        m_args = m_context.getArguments();
    }

    public void start() throws Exception
    {
        final Hashtable data = new Hashtable();
        data.put(Observer.class.getName(), this);
        Main.startup(m_args, data, false);
    }

    public void stop()
    {
        Main.shutdown();
    }

    public void destroy()
    {
    }

    public void update(final Observable observable, final Object arg)
    {
        final String command = (null != arg) ? arg.toString() : "";
        if (command.equals("restart"))
        {
            log("CommonsDaemon: restart requested.");

            m_controller.reload();
            log("CommonsDaemon: restart completed.");
        }
        else if (command.equals("shutdown"))
        {
            log("CommonsDaemon: shutdown requested.");
            m_controller.shutdown();

            log("CommonsDaemon: shutdown completed.");

        }
        else
        {
            throw new IllegalArgumentException("Unknown action " +
command);
        }
    }

    private void log(final String message)
    {
        System.out.print("CommonsDaemon: ");
        System.out.println(message);
        System.out.flush();
    }
}



Re: phoenix and commons daemon (jsvc) not seems to work

Posted by Stefano Bagnara <ap...@bago.org>.
Norman Maurer wrote:
>  I created a jar called phoenix-daemon-loader.jar which contains just
> one class which is needed for jsvc to invoke phoenix. The class will be
> posted on the end of the email.. I compiles jsvc and move it to the bin
> path of james. I also moved the commons-daemon.jar and
> phoenix-daemon-loader.jar in the dir.

Hi Norman,

I also tried with this class (add unpriviledgedDelay), but it didn't work:

/**
  * Phoenix launcher using Commons daemon.
  */
public class CommonsDaemonLauncher implements Daemon, Observer {
     private DaemonContext m_context;

     private DaemonController m_controller;

     private String[] m_args;

     private boolean m_debugEnabled = false;

     private int unpriviledgedDelay = 60;

     public void init(final DaemonContext daemonContext) throws Exception {
         m_context = daemonContext;
         m_controller = m_context.getController();
         m_args = m_context.getArguments();
         for (int i = 0; i < m_args.length; i++) {
             if ("-d".equals(m_args[i]) || 
"--debug-init".equals(m_args[i])) {
                 m_debugEnabled = true;
             }
             if (m_args[i].startsWith("--unpriviledged-delay=")) {
                 unpriviledgedDelay = new 
Integer(m_args[i].substring(m_args[i].indexOf("=")+1)).intValue();
             }
         }
     }

     public void start() throws Exception {
         final Hashtable data = new Hashtable();
         data.put(Observer.class.getName(), this);

         Main.startup(m_context.getArguments(), data, false);
         Thread.sleep(1000*unpriviledgedDelay );
     }

     public void stop() throws Exception {
         Main.shutdown();
     }

     public void destroy() {
     }

     public void update(final Observable observable, final Object arg) {
         final String command = (null != arg) ? arg.toString() : "";
         if (command.equals("restart")) {
             if (m_debugEnabled) {
                 log("CommonsDaemon: restart requested.");
             }

             m_controller.reload();

             if (m_debugEnabled) {
                 // Should never get here???
                 log("CommonsDaemon: restart completed.");
             }
         } else if (command.equals("shutdown")) {
             if (m_debugEnabled) {
                 log("CommonsDaemon: shutdown requested.");
             }

             m_controller.shutdown();

             if (m_debugEnabled) {
                 // Should never get here???
                 log("CommonsDaemon: shutdown completed.");
             }
         } else {
             throw new IllegalArgumentException("Unknown action " + 
command);
         }
     }

     private void log(final String message) {
         System.out.print("CommonsDaemon: ");
         System.out.println(message);
         System.out.flush();
     }
}


Stefano


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[WORKS NOW !] Re: phoenix and commons daemon (jsvc) not seems to work

Posted by Norman Maurer <nm...@byteaction.de>.
Hi guys,

after i some hard hours we now able to start james with commons
daemon :-) So we now able to start james as root and "drop" privileges
after that to a other user. This is a big security enhancment .

Here is what i did to get it work:
1. Create a new jar which holds the necassary class to invoke phoenix
via commons daemon.

2. put commons-daemon.jar and phoenix-daemon-loader-0.1.jar ( the new
class) in the bin folder of james.

3. put jsvc.tar.gz in the bin directory of james ( this is the tools
which must be unpacked and compiled to start it). I put it in the bin
cause tomcat do this also. After unpack and compile it this should be
placed in the bin directory of james

4. Add a new startup script which start james via jsvc. In the script
you can modify some variables to set the new user james should run as
etc.

Please note that you need to change the user of the unpacked james
recursive to the user you want to run james as.

If noone have probles with this i whould commit it to trunk so all can
test. With commons daemon its also possible to run it as windows.. so
maybe we want to deprecate the wrapper.* and use procrun.exe (commons
daemon).

I whould also like to put this new feature in 2.3 cause its really a
nice enhancment and not needed to use .

Big thx goes out to Jean-frederic Clere which helps me to understand how
to get it to work :-) THX!!!!

bye
Norman

Am Mittwoch, den 19.07.2006, 10:32 +0200 schrieb Stefano Bagnara:
> Norman Maurer wrote:
> >  I created a jar called phoenix-daemon-loader.jar which contains just
> > one class which is needed for jsvc to invoke phoenix. The class will be
> > posted on the end of the email.. I compiles jsvc and move it to the bin
> > path of james. I also moved the commons-daemon.jar and
> > phoenix-daemon-loader.jar in the dir.
> 
> Hi Norman,
> 
> I also tried with this class (add unpriviledgedDelay), but it didn't work:
> 
> /**
>   * Phoenix launcher using Commons daemon.
>   */
> public class CommonsDaemonLauncher implements Daemon, Observer {
>      private DaemonContext m_context;
> 
>      private DaemonController m_controller;
> 
>      private String[] m_args;
> 
>      private boolean m_debugEnabled = false;
> 
>      private int unpriviledgedDelay = 60;
> 
>      public void init(final DaemonContext daemonContext) throws Exception {
>          m_context = daemonContext;
>          m_controller = m_context.getController();
>          m_args = m_context.getArguments();
>          for (int i = 0; i < m_args.length; i++) {
>              if ("-d".equals(m_args[i]) || 
> "--debug-init".equals(m_args[i])) {
>                  m_debugEnabled = true;
>              }
>              if (m_args[i].startsWith("--unpriviledged-delay=")) {
>                  unpriviledgedDelay = new 
> Integer(m_args[i].substring(m_args[i].indexOf("=")+1)).intValue();
>              }
>          }
>      }
> 
>      public void start() throws Exception {
>          final Hashtable data = new Hashtable();
>          data.put(Observer.class.getName(), this);
> 
>          Main.startup(m_context.getArguments(), data, false);
>          Thread.sleep(1000*unpriviledgedDelay );
>      }
> 
>      public void stop() throws Exception {
>          Main.shutdown();
>      }
> 
>      public void destroy() {
>      }
> 
>      public void update(final Observable observable, final Object arg) {
>          final String command = (null != arg) ? arg.toString() : "";
>          if (command.equals("restart")) {
>              if (m_debugEnabled) {
>                  log("CommonsDaemon: restart requested.");
>              }
> 
>              m_controller.reload();
> 
>              if (m_debugEnabled) {
>                  // Should never get here???
>                  log("CommonsDaemon: restart completed.");
>              }
>          } else if (command.equals("shutdown")) {
>              if (m_debugEnabled) {
>                  log("CommonsDaemon: shutdown requested.");
>              }
> 
>              m_controller.shutdown();
> 
>              if (m_debugEnabled) {
>                  // Should never get here???
>                  log("CommonsDaemon: shutdown completed.");
>              }
>          } else {
>              throw new IllegalArgumentException("Unknown action " + 
> command);
>          }
>      }
> 
>      private void log(final String message) {
>          System.out.print("CommonsDaemon: ");
>          System.out.println(message);
>          System.out.flush();
>      }
> }
> 
> 
> Stefano
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
> 
> !EXCUBATOR:1,44bdee2f43381065220303!