We had an internal discussion on this and following is the solution.

1) Find the PID of the Java process using the following code segment.
Basically this is only required when the Carbon is running on Unix based
systems.

        byte[] bo = new byte[100];
        String[] cmd = {"bash", "-c", "echo $PPID"};
        Process p;
        try {
            p = Runtime.getRuntime().exec(cmd);
        } catch (IOException e) {
            //ignored. We might be invoking this on a Window platform.
Therefore if an error occurs
            //we simply ignore the error.
            return;
        }

        try {
            int bytes = p.getInputStream().read(bo);
        } catch (IOException e) {
            log.error(e.getMessage(), e);
        }

        String pid = new String(bo);

2) Invoke the Main class from the script without exec. This will maintain a
parent-child relationship between the server script and the Java process.
Hence the restart will work.

Thanks,
Sameera.

On Tue, May 8, 2012 at 2:55 PM, Sameera Jayasoma <[email protected]> wrote:

> Hi Devs,
>
> We have used -Dcarbon.pid=$$ to pass the PID of the Java Process as an
> system variable.
>
> If you execute the following command from the wso2server.sh, value of the
> $$ will be the PID of the parent process. i.e. process in which the bash
> script runs.
>
> *exec java .....*
>
> In order the get the Java process ID, you need to do something like
> following. Then you get the PID of the Java process.
>
> *exec exec java .....*
>
> But in this scenario, our graceful restart/restart functionality fails.
> This can be clear visible, when you run integration tests. Therefore, we
> need to use ''exec java .." command in the wso2server.sh to fix the restart
> issue.
>
> If thats the case, we need to find a better way to obtain the PID of the
> Java process.
>
> We found on blog[1]. Looks like there is no platform-independent way to do
> this.
>
> Any thoughts?
>
> Thanks,
> Sameera.
>
> --
> Sameera Jayasoma
> Technical Lead
>
> WSO2, Inc. (http://wso2.com)
> email: [email protected]
> blog: http://tech.jayasoma.org
>
> Lean . Enterprise . Middleware
>



-- 
Sameera Jayasoma
Technical Lead

WSO2, Inc. (http://wso2.com)
email: [email protected]
blog: http://tech.jayasoma.org

Lean . Enterprise . Middleware
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to