Centos tmux restart script

Discussion in 'Systems Administration' started by KaareZ, Jun 7, 2014.

  1. Straight from your link "Tmux was created to provide a simple, modern, lightweight, BSD-licensed alternative to GNU Screen. In general, the design goals for tmux ensure it is a relatively fast and lightweight application. The client/server architecture also ensures that increases of resource usage for multiple sessions are minimized."
    With many players online and many rapid things being printed in the console screen begins to use more system resources; TMUX is far more efficient and lightweight.
     
    • Like Like x 1
  2. Is there any way to do something like this with tmux?
     
    • Like Like x 1
  3. If screen had tmux's simplicity I would defiantly use it in this case. But such a simple task like we have here, can't be resolved easily..
     
  4. Scrolling doesn't work, and it has a few bugs.
    How does it NOT have that simplicity?
    You roll your own config, how much more clean and simple can it get?
     
  5. Because this is a minecraft/java issue, not screen.
    The same thing would happen with screen.
    /restart stops and starts as what you'd call a "system service", just like you can't connect and see the console of i.e. mysqld unless you close it and start it in no-daemon mode...
     
  6. Don't get me wrong but it executes the script supplied in the spigot.yml. So why not create a new screen or tmux with that and terminate the old one.
     
  7. It doesn't afaik - that only happens on crashes.
    If it did, this would be easy as balls - much easier than with screen ¬¬' (I tried once).

    Also, using the sript I supplied and using /stop instead would achieve exactly what OP wants.
     
  8. So use commands.yml
     
  9. @KaareZ , the script I posed on page one will do exactly what you want if you use /stop.
    Doing it so /restart works will take a few minutes of effort, where this will take less than one.
     
  10. I have a working start script now.
    Code (Text):

    #!/bin/bash
    echo "skyblock just started"
    tmux new-session -d -s mc-skyblock -n /home/servers/skyblock
    tmux send-keys -t mc-skyblock:0 "java -Xmx4G -Xms4G -jar spigot.jar" C-m
     
    And a restart script.
    Code (Text):

    #!/bin/bash
    tmux send-keys -t mc-skyblock:0 "say server restarts in 10 seconds" C-m;
    sleep 10s;
    tmux send-keys -t mc-skyblock:0 "stop" C-m;
    sleep 5s;
    bash start.sh
     
    When I run
    Code (Text):
    bash restart.sh
    the server restarts. So the scripts are working.
    The problem is, when I type /restart it just shuts down the server. The "Server restarts in 10 seconds" message does not even apear and the server stop, which means it does not even run restart.sh

    In spigot.yml I have configured the restart script to be ./restart.sh

    Please help
     
  11. Use my solution.
     
  12. Cant I make spigot run restart.sh?
     
  13. No, but if you use /stop, it will have the same effect.
     
  14. So spigot wont run restart.sh??
    I dont see the point of the config option.
     
  15. It will, but using my method is far easier.
     
  16. So I have this bash now.

    Code (Text):
    #!/bin/bash
    while true
    do
        tmux new-session -d -s mc-hungergames2 -n /home/servers/hungergames2
        tmux send-keys -t mc-hungergames2:0 "java -Xmx2G -Xms2G -jar /home/jars/spigot.jar" C-m
        echo "hungergames2 just started"
            echo "You have three seconds to do 'Ctrl+C' to stop the server. The server will auto restart in three seconds."
        sleep 3
    done
    I get this error:
    start.sh: line 9: syntax error near unexpected token `done'


    And when I remove "done" I get this:
    start.sh: line 9: syntax error: unexpected end of file


    Please help