https://issues.apache.org/bugzilla/show_bug.cgi?id=47881

--- Comment #2 from qingyang.xu <qingyang...@qunar.com> 2009-10-08 16:20:38 PDT 
---
(In reply to comment #1)
> Actually, I do not see startd and stopd commands to be documented anywhere.
> Maybe we can just safely remove them?
> 
> With startd, Tomcat will exit immediately upon startup. Though it may be 
> useful
> for testing config files.
> 
> With stopd ... you cannot stop server that is not running.
> 
> And if you have an instance of Bootstrap, you can call load/start/stop
> directly, not relying on how Bootstrap#main() parses the arguments.
> 
> Regarding the patch: args are not used in "stopd", that line can be omitted
> completely, or we can do as OP proposes. Regarding "startd": yes, the fix is
> correct.

(In reply to comment #1)
> Actually, I do not see startd and stopd commands to be documented anywhere.
> Maybe we can just safely remove them?
> 
> With startd, Tomcat will exit immediately upon startup. Though it may be 
> useful
> for testing config files.
> 
> With stopd ... you cannot stop server that is not running.
> 
> And if you have an instance of Bootstrap, you can call load/start/stop
> directly, not relying on how Bootstrap#main() parses the arguments.
> 
> Regarding the patch: args are not used in "stopd", that line can be omitted
> completely, or we can do as OP proposes. Regarding "startd": yes, the fix is
> correct.

The only difference between 'startd' and 'start' is that 'startd' doesn't
invoke Catalina's await() method after the server has been started, or 'startd'
doesn't need to allocate a 'SHUTDOWN' port to listening to be sent a 'SHUTDOWN'
message. 'stopd' is the counterpart of 'stop'. If tomcat is started by
'startd', you must invoke 'stopd' to shutdown it, otherwise the server can't 
be stopped, because 'stop' invoke Catalina's stopServer() method, which relies
on the allocated 'SHUTDOWN' port exclusively. On the contrary, 'stopd' invokes
Catalina's stop() method instead, which invoke server's stop() method directly.
Below is the two different methods invoked by 'stop' and 'stopd':


//invoked by 'stop'
public void stopServer() {
        stopServer(null);
    }

    public void stopServer(String[] arguments) {

        if (arguments != null) {
            arguments(arguments);
        }

        if( server == null ) {
            // Create and execute our Digester
            Digester digester = createStopDigester();
           
digester.setClassLoader(Thread.currentThread().getContextClassLoader());
            File file = configFile();
            try {
                InputSource is =
                    new InputSource("file://" + file.getAbsolutePath());
                FileInputStream fis = new FileInputStream(file);
                is.setByteStream(fis);
                digester.push(this);
                digester.parse(is);
                fis.close();
            } catch (Exception e) {
                log.error("Catalina.stop: ", e);
                System.exit(1);
            }
        }

        // Stop the existing server
        try {
            if (server.getPort()>0) {
                String hostAddress =
InetAddress.getByName("localhost").getHostAddress();
                Socket socket = new Socket(hostAddress, server.getPort());
                OutputStream stream = socket.getOutputStream();
                String shutdown = server.getShutdown();
                for (int i = 0; i < shutdown.length(); i++)
                    stream.write(shutdown.charAt(i));
                stream.flush();
                stream.close();
                socket.close();
            } else {
                log.error(sm.getString("catalina.stopServer"));
                System.exit(1);
            }
        } catch (IOException e) {
            log.error("Catalina.stop: ", e);
            System.exit(1);
        }

    }


    // invoked by 'stopd'
    public void stop() {

        try {
            // Remove the ShutdownHook first so that server.stop() 
            // doesn't get invoked twice
            if (useShutdownHook) {
                Runtime.getRuntime().removeShutdownHook(shutdownHook);
            }
        } catch (Throwable t) {
            // This will fail on JDK 1.2. Ignoring, as Tomcat can run
            // fine without the shutdown hook.
        }

        // Shut down the server
        if (server instanceof Lifecycle) {
            try {
                ((Lifecycle) server).stop();
            } catch (LifecycleException e) {
                log.error("Catalina.stop", e);
            }
        }

    }


My suggestion: We don't need to remove 'startd' and 'stopd', they are useful in
some situations. The only place we need to correct is the Bootstrap's main()
method, as in the patches I have submitted. Thanks!

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to