Asynchronous shell commands with screen

I am trying to use ant + scp to execute a script on a remote server.

The script on the remote server is pretty simple, it starts a game server written in java:

game_server.sh:

java -Xms500M -Xmx500M -jar game.jar

      

ant build.xml:

<?xml version="1.0" ?>
<project default="restart_game_server" name="server"> 
    <target name="restart_game_server"> 
        <sshexec host="x.x.x.x" username="root" password="xxx" command="cd xxx; ./game_server.sh" trust="true" />
    </target>
</project>

      

When I run "ant" command in terminal (mac os), game_server.sh on remote server succeeds, but the problem is this:

the "ant" command is blocked because "game_server.sh" will never return.

I tried to solve this problem by running "game_server" on "screen" but I cannot figure out how to do it in a shell script, I tried something like:

# kill the game sever first
fuser -k -n tcp 9988
# resume the last screen or start a new one
screen -R
# move to the folder where the script is located
cd xxxx
# run script
./game_server.sh

      

But I don't know how to exit the screen using shell command instead of keyboard (c + a + d)

Any suggestion would be appreciated, thanks :)

EDIT:

Tried using "&" but still blocked.

Here is the output of the ant command, you can see how it is blocked:

root: ant
Buildfile: build.xml

restart_game_server:
  [sshexec] Connecting to x.x.x.x.x:22
  [sshexec] cmd : fuser -k -n tcp 9988; cd xxxxx; ./game_server.sh &
  [sshexec] 9988/tcp:         
  [sshexec]  12729
  [sshexec]   
  [sshexec] game sever log
  [sshexec] game sever log
  [sshexec] game sever log
  [sshexec] game sever log
  [sshexec] game sever log
  [sshexec] game sever log
  .......
  BLOCKED !!!!!

      

+3


source to share


2 answers


You can try running game_server.sh in the background like this without using the screen at all:

./game_server.sh &

      



or you can try changing your build.xml file like this:

<?xml version="1.0" ?>
<project default="restart_game_server" name="server"> 
    <target name="restart_game_server"> 
        <sshexec host="x.x.x.x" username="root" password="xxx" command="cd xxx; ./game_server.sh &" trust="true" />
    </target>
</project>

      

+1


source


Use screen -d -m

to launch the screen in Off Mode.



See the man page for details .

0


source







All Articles