Start script with screen

Discussion in 'Systems Administration' started by ferrydekker, Mar 19, 2020.

  1. Hi, I have a start script in screen, so that I can always easily detach and attach to my server console. Now I want to create a system, that if the server crashes or I use /stop, then that the .sh file asks me If I want to reboot, and after 5 seconds it auto-reboots, and if I do ctrl + C, it shutdowns instead of reboots. How do I do it? this is the code i'm wanting to use.
    Code (Text):
    #!/bin/bash

    while true
    do
        screen -A -m -d -L -S server java -Xms100M -Xmx2750M -jar spigot-1.15.2.jar nogui
        echo "If you want to completely stop the server process now, press Ctrl+C before the time is up!"
        echo "Rebooting in:"
        for i in 5 4 3 2 1
        do
            echo "$i..."
            sleep 1
        done
        echo "Rebooting now!"
    done