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

  1. SSH from Server 1 -> Server 2 and run a script
  2. Have the script do a number of things to prepare a new user
  3. 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 1from shell, works just fine. When I put it in the bash script

mkuser newuser
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

echo Maxram $maxram

echo Creating server for user.
sudo -u $newuser bash << EOF
cd ~
while true
cd server
java -Xms512M -Xmx$maxram -jar server.jar
cd ..
sleep 30
echo Out
  • 2
    Don't run services in screen. This is horribly bad advice (that a lot of websites unfortunately still push) and completely inappropriate for production. It's almost always inappropriate for development too. Set up a proper systemd unit for it. – Michael Hampton Nov 12 '18 at 13:31
  • Alright, I can do that. I tried making my own service but it crashes even though when I run the same command that ExecStart is, it runs fine. I found this(minecraft.gamepedia.com/Tutorials/Server_startup_script) but it looks like it still uses screens in order to communicate with the process. Any suggestions? – quantomworks Nov 13 '18 at 9:15
  • Well if it's Minecraft you're kind of screwed because the developers don't know what they are doing and require commands to be sent to it on standard input. This is an absolute no-no for a service, but they did it anyway. You could ask them to do something reasonable instead, but that may or may not ever happen... – Michael Hampton Nov 13 '18 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.