在linux脚本中运行远程java服务器 [英] Run remote java server in linux script

查看:193
本文介绍了在linux脚本中运行远程java服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Java中实现了一个名为Provider的服务器,以及用于启动它的linux脚本。

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

何时我想在不同的机器上执行以下脚本(machine2)

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

问题是,在运行上面的脚本后,它不会返回控制台,它会挂起,虽然Provider会启动。

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

我已经分析了像Glassfish域一样的类似概念。执行

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 "$?"

推荐答案

我认为问题是远程 sshd 不会关闭ssh会话,因为在后台仍然有一个运行的java进程尝试写输出。

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.

尝试将后台进程stdout和stderr重定向到/ dev / null;例如。

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

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

这篇关于在linux脚本中运行远程java服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆