Linux watchdog script?

Ba
- in Servers
4

Since I'm upgrading from a Windows to a Linux ubuntu server, I have a question.

I have this script (bat) which restarts my server as soon as it goes off (e.g. Due to a crash).

So roughly: If the console is closed - start it again after a delay!

I can't just copy the code, can I? How can I rewrite it? Or is there another option?

Ps: Just getting to know Linux.

greeting

Here is the code:

echo off

cls

echo This script monitors the server!

title Minecraft WatchDog

: StartServer

TIMEOUT / T 60

start / wait java -Xmx2548M -jar paper.jar nogui

echo (% time%) Server closed / crashed… Restart!

goto StartServer

Da

Ubuntu also uses systemd.

You can use the service and the entry in the configuration file

Restart = on-abort

take up. But I can't tell you how it's done with Ubuntu. But they have a forum. http://wiki.ubuntuusers.de/Links/Programmierung

Ba

Many thanks for the answer!

Po

The script is for Windows, it won't work that way on Linux.

for Linux it should look like this:

#! / bin / bash

cd $ path-to-server-directory
echo "This script is monitoring the server"
while true; do
./start -wait java -Xmx2548M -jar paper.jar nogui
echo "$ (date): Server closed / crashed… Restart!"
sleep 60
done

Replace $ path-to-server-directory with the path where the server was installed.

The script still has potential for optimization, that's just a conversion of your script above.

the line where the server is started must probably be adjusted again. I've never started a Minecraft server before.

It would be better, however, if you create a systemd unit from it, since the watchdog functionality is already integrated.

https://wiki.ubuntuusers.de/systemd/Units/

Ba

Thank you for the good answer!