Ahmet Karakaya
Ahmet Karakaya

Reputation: 10139

Run remote java server in linux script

I have a Server implemented in Java named Provider, and linux script to start it.

#!/bin/bash
echo "Provider"
$JAVA_HOME/bin/java -cp /tmp  Provider&
$JAVA_HOME/bin/java -version
rm  /tmp/pid
echo "$!"> /tmp/pid
echo "Provider-finish"
exit 0

When I want to execute the following script at different machine (machine2)

root@machine1:/tmp# ssh  machine2/tmp/runScript.sh
Provider
java version "1.6.0_29"
Java(TM) SE Runtime Environment (build 1.6.0_29-b11)
Java HotSpot(TM) Client VM (build 20.4-b02, mixed mode, sharing)
Provider-finish
Waiting for connection

The problem is that after running above script, it does not return console, it hang-up though Provider gets started.

I have analized similar concepts like Glassfish domain starting. by executing

ssh machine2 asadmin start-domain

it returns console without any problem so I can get execution status "$?"

Upvotes: 1

Views: 381

Answers (1)

Stephen C
Stephen C

Reputation: 718678

I think that the problem is that the remote sshd won't close the ssh session because there is still a java process running in the background that might try to write output.

Try redirecting the background processes stdout and stderr to "/dev/null"; e.g.

$JAVA_HOME/bin/java -cp /tmp Provider > /dev/null 2>&1 &

Upvotes: 2

Related Questions