How do I start and stop multiple servers on CentOS?

Discussion in 'Server & Community Management' started by TheHoodmaster, Aug 14, 2013.

  1. I've used riot shielders scripts, but they don't work, it's always saying screen is terminating.
     
  2. joehot200

    Supporter

    Make a script that manages them all :)
     
  3. Make me one? Pwitty pwease?
     
  4. joehot200

    Supporter

    I dont know your server directories, so i would be unable to, however, it would be a bit like this:

    <Please note you will have to start screens for them, i may know how to do that but am not sure, please note any line containing "screen" or "exit" may be incorrect, and i will probably have unnececcary code there>

    while true
    do
    screen
    java -Xincgc -Xmx10G -jar /home/yourserver/craftbukkit.jar
    echo server 1 started
    exit
    screen
    java -Xincgc -Xmx10G -jar /home/yourserver2/craftbukkit.jar
    echo server 1 started
    exit
    screen
    java -Xincgc -Xmx10G -jar /home/yourserver3/craftbukkit.jar
    echo server 1 started
    exit
    screen
    java -Xincgc -Xmx10G -jar /home/yourserver4/craftbukkit.jar
    echo server 1 started
    exit
    echo Its off..sleeping for 5
    sleep 5
    done


    Now for stopping the servers, just have 1 other script, with the line:
    pkill "java" (PLEASE NOTE THERE WILL BE A BETTER WAY TO DO THIS AS IT FORCE-STOPS THE SERVER)
    echo all servers now stopped, and will be restarting in 5 seconds.
     
  5. Wasn't really expecting you to make a whole script, but this will will help me. Thanks.
     
  6. jtaylor69

    jtaylor69 Retired Moderator
    Retired

    What about stop?
     
    • Agree Agree x 1
  7. joehot200

    Supporter

    You would have to go to the server console(s) and type that, and i am not sure how to get to the server console from a script.
     
  8. Code (Text):
    #!/bin/sh
     
    screen -S server1 -X stuff "say Server is stopping"
    screen -S server1 -X eval "stuff \015"
    screen -S server1 -X stuff "stop"
    screen -S server1 -X eval "stuff \015"
    echo Server1 Stopped
     
    screen -S server2 -X stuff "say Server is stopping"
    screen -S server2 -X eval "stuff \015"
    screen -S server2 -X stuff "stop"
    screen -S server2 -X eval "stuff \015"
     
    echo Server2 Stopped
     
    echo Well... All Server have been stopped xD Dont forget to start them again.


    Yeah... quick and dirty. :)
     
    • Like Like x 1
    • Informative Informative x 1
  9. Pardon my Linux nubiness, but whats \015 for?
     
    • Agree Agree x 1
  10. joehot200

    Supporter

    Code i posted above is in a loop so... as soon as all the servers stop the script will execute itself again automatically.
     
  11. That will press enter to send the command.

    Sure. With your script, the last echo isn't needed.
     
    • Informative Informative x 1
  12. Does Joehots script work with centos?