Issues with auto restart script - Linux Ubuntu 14.04

Discussion in 'Spigot Help' started by Erlpil, May 11, 2015.

  1. Hello!

    I want to set up an auto restart script for my server running on Linux Ubuntu 14.04.

    Issue: I have a server running a game plugin that shuts the server down after each game and needs a restart to start the next game.

    Additional info: This ubuntu server is running several servers in different screens.
    I have tried various scripts. (Been searching the web for over 90 min with no luck)
    I have set the script in spigot.yml and set restart-on-crash: true.
    Using Spigot 1.8.3
    My normal startup script: java -Xmx4G -Xms256m -XX:MaxPermSize=128M -jar spigot-1.8.3.jar nogui

    Does anyone know a way of setting up a script that works on Ubuntu and will restart my server once the plugin has shut it down?


    Thanks in advance! :)
     
  2. Restart the server with /restart instead of /stop :) Btw the nogui parameter is not necessary.
     
  3. Might be a permissions problem with the script. Do you have any output from the server when it tries to run the script, or does it not run at all?
     
  4. AventLV:
    My start script:
    Code (Text):
    java -Xmx4G -Xms256m -XX:MaxPermSize=128M -jar spigot-1.8.3.jar nogui
    With /restart this just turns my server off.

    The plugin I am using shuts the server down for me. I am not in control of that.

    Roki:
    Yes, that might be an issue.

    I tried this script that I found on the spigot forums:

    Code (Text):
    while true
    do
    java -Xmx4G -Xms256m -XX:MaxPermSize=128M -jar spigot-1.8.3.jar nogui
    echo Its off..sleeping for 5
    sleep 5
    done
    Error:
    Code (Text):
    ./start.sh: 6: ./start.sh: Syntax error: "done" unexpected (expecting "do")
    This says there is something wrong witht he script, but many users said it worked... I am confused.
     
  5. start the server in a screen, then it works.

    #!/bin/bash
    screen -dmS minecraft java -Xmx4G -Xms256m -XX:MaxPermSize=128M -jar spigot-1.8.3.jar
     
  6. AgentLV:
    Changed the start up script to the one you sent me.
    Ran it like this (in a screen)
    Code (Text):
    sudo ./start.sh
    Error:
    Code (Text):
    sudo: unable to execute ./start.sh: No such file or directory
     
  7. That's a Syntax error. Ubuntu doesn't understand "done", so it doesn't run the script. Try "fi" instead of "done".

    Hope this helps!

    *EDIT*

    Nevermind... Seems like fi is only used for ending if statements. It may work, but it may not :)
     
    • Optimistic Optimistic x 1
  8. Roki:
    Thanks for the suggestion.
    Error:
    Code (Text):
    ./start.sh: 6: ./start.sh: Syntax error: "fi" unexpected (expecting "do")
    I must be doing something fundamentaly wrong...
     
  9. Haha... Yeah my bad. Not that good with bash scripting. I edited my post above with an explination haha...

    So after taking another look at the error it seems that you may be missing "[" and "]" around your while condition. Try "while [ true ]".

    Look here for more info about bash loops.
     
    • Optimistic Optimistic x 1
  10. I ran this script:
    Code (Text):
    while [ true ]
    do
    java -Xmx4G -Xms256m -XX:MaxPermSize=128M -jar spigot-1.8.3.jar nogui
    echo "Its off..sleeping for 5"
    sleep 5
    done
    Error:
    Code (Text):
    ./start.sh: 6: ./start.sh: Syntax error: "done" unexpected (expecting "do")
     
  11. This thread almost gave me cancer. Here OP, take this:

    Code (Text):
    #!/usr/bin/env bash

    while true; do
      java -Xmx4G -XX:+UseConcMarkSweepGC -jar spigot-1.8.3.jar
      echo "Server restarting in 5 seconds. Press Ctrl-C to cancel."
    done
    You don't need Xms. Please tell me you're on Java 8 as well.
    If you're running the script as a standalone executable, make sure it has execution permission (chmod +x start.sh).
     
    • Informative Informative x 2
  12. Got to it first. Thank you. I try to help everyone i can, even if i only know something about the topic. :)
     
  13. Thanks for the sugestion frash23.

    Now I know something is fundamentaly wrong. When I run this script:

    Code (Text):
    #!/usr/bin/env bash

    while true; do
      java -Xmx4G -XX:UseConcMarkSweepGC -jar spigot-1.8.3.jar
      echo "Server restarting in 5 seconds. Press Ctrl-C to cancel."
    done
    I get the error:
    Code (Text):
    : No such file or directory
    I tried to delete the file and add it back, also under a new name. Same error.
    Yes, I have used chmod +x start.sh

    Java version:
    "1.7.0_79" OpenJDK Runtime Enviorment
     
  14. I have a suspicion you're typing the script manually and typo'ing.
    Post screenshots of these commands:
    Code (Text):
    cat start.sh
    uname -a
    ls -lha start.sh
     
  15. Are you within the same directory as the script when you try running it?
     
  16. You're missing a `+` after the -XX flag, though I don't see why that should throw such an error. Copy-paste my original script and see if it works.
     
  17. I added the +
    Code (Text):
    #!/usr/bin/env bash

    while true; do
      java -Xmx4G -XX:+UseConcMarkSweepGC -jar spigot-1.8.3.jar
      echo "Server restarting in 5 seconds. Press Ctrl-C to cancel."
    done
    Still throws me the error:
    Code (Text):
    : No such file or directory
     
  18. How are you executing it it? You should only need to write "./start.sh" in your console.
     
  19. I am running the command like this:
    Code (Text):
    sudo ./start.sh