I'm essentially trying to combo Create screen and run command without attaching and another answer that allowed me to run a script as another user. I want to
- SSH from Server 1 -> Server 2 and run a script
- Have the script do a number of things to prepare a new user
- After the script is done, start a screen that runs a java process and restarts it if it crashes.
I've got one and two down. When testing out three using screen -d -m ./startServer.sh newUser 1
from shell, works just fine. When I put it in the bash script
mkuser newuser
...otherthings...
screen -d -m ./startServer.sh newuser 1
It does not want to run.
When I call it from node using spawn, it lives on the same process as the node application and the stdout never closes, making it seem like it never goes into a screen at all. Whats worse is, when I close down node from server1, it the bash process still exists in top
and I have to sigkill it.
Here is startServer.sh
#!/bin/bash
newuser=$1
maxram="$2""G"
echo Maxram $maxram
echo Creating server for user.
sudo -u $newuser bash << EOF
cd ~
while true
do
cd server
java -Xms512M -Xmx$maxram -jar server.jar
cd ..
sleep 30
done
EOF
echo Out