Centos tmux restart script

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

  1. Hello. Im running my servers with tmux (In putty).
    How can I make a restart script, not an auto restart script which make the server restart every 24 hours, but a script which allows you do do "/restart" or if the server crash.

    So how does the script look?
    Code (Text):
    java -Xmx4G -Xms4G -jar spigot.jar
    ?
    And how does it work with the tmux sessions? How can I make the server start in the same session/pane/window???


    Thanks
     
  2. Arrow up will select the latest run command, doing it again will "scroll" further up in history.

    Fun fact: This also works in minecraft chat.


    But really, put it in an infinite loop:
    Code (Text):
    while true
    do
        java -Xmx4G -Xms4G -jar spigot.jar
            echo "You have five seconds to do 'Ctrl+C' to stop the server. The server will auto restart in five seconds."
        sleep 5
    done
    That will repeat the contesnts of the loop forever.

    After the java process finishes, it will print that information, sleep (wait) for five seconds, then loop. (Similar to restarting.)
     
  3. I know that... Its not that I mean. Im not to lazy to write java -Xmx4G -Xms4G -jar spigot.jar
    I need a restart script, so I ingame can do /restart. And it needs not to open in a new tmux session
     
    • Funny Funny x 1
  4. How would that script work with tmux? Would it start in the same session?
     
  5. Don't use /restart.

    I am afraid what you are trying to achieve is impossible.
     
  6. Okay. Why not use /restart?
     
  7. Because it starts a transparent process, obviously?
     
  8. What shall I do when I want to restart the server then?
     
  9. >Go on SSH
    >Connect to TMUX
    >Select pane containing server
    >Write "stop"
    >Wait a few seconds
    >Press arrow up, then enter
     
  10. Can't you have something like this:
    Code (Text):
    #!/bin/bash
    screen -dmS Minecraft java -jar -Xmx4G -Xms4G Spigot.jar
     
  11. That looks more like a startup-script for init.d
     
  12. Defiantly not. If that's executed it will start the server in a screen.
     
  13. Would that be possible with tmux instead of screen?
    Edit: And what should I call the script? start.sh?
     
  14. If you're using tmux, you should know how to use it. I don't use it because I prefer screen. But sure, start.sh seems reasonable.
     
  15. "I don't use it because I prefer screen."
    You obviously don't "prefer" screen, you need to know both to say that.
    If you knew how to use tmux, you would likely "prefer" it.
     
  16. I like the simplicity and easiness of screen. I attempted to use it and It wasn't for me...
    Tmux gets very messy very quick.

    Again they both have their pro's and con's. And it is personal preference. If you really want to start a debate over this. Don't start it with me please.
     
  17. I can't name any pro of screen that tmux can't do.

    Tmux has scrolling, and is much cleaner than tmux.
     
    • Agree Agree x 1
  18. This. Screen has absolutely no advantages and will cause you more issues as the server size increases
     
  19. Not even going to bother carrying this on. It's immature and not helping @KaareZ.

    Also dmS starts screen as a daemon, meaning if the minecraft server stops, the screen will terminate.
    Then you can use the script I posted above to launch a new screen.
     
  20. Please tell me more about how it will cause issues?
    http://www.wikivs.com/wiki/screen_vs_tmux