• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Linux Auto Restarter + Screenlog save + error + output list.

kito2

www.masteria.net
Joined
Mar 9, 2009
Messages
3,766
Solutions
1
Reaction score
225
Location
Chile, Santiago
Hello,

I have 3 scripts which I would like to mix and make just one but I am a bit confused on how to make them work all, so I come here asking for help. Maybe some of you could help me on this:

This script is used to start the server and to save a screenlog of the output, minimizing on a screen:
Code:
#!/bin/sh
#
# Startup and signals management script for TheForgottenServer
#
case "$1" in
  start)
        ulimit -c unlimited
        echo -n "Starting ... "
       screen -LAdmS root ./tfs
        echo "done."
        ;;
  stop)
        echo -n "Shutting down: "
        killall -TERM tfs
        echo "done."
        ;;
  kill)
        echo -n "Killing ... "
        killall -KILL tfs
        echo "done."
        ;;
  *)
        echo "Usage: $0 {start|stop|kill}"
        exit 1
esac

exit 0

This script auto-restarts the server if it crashes:
Code:
#!/bin/bash
ulimit -c unlimited
while true; do ./theforgottenserver; done

This script should "screen" and save the output and an error file when it closes (needed gdb):
Code:
#!/bin/bash
ulimit -c unlimited
while true; do screen -LAdmS root ./tfs --log-file "output.txt" "error.txt"; done

The idea is to have a simple code which would restart the server when it crashes, save the log file somewhere and also use the gdb application in order to debug when it crashes and save the log.

Could someone help me? Thanks!

@StreamSide
 
Code:
#!gdb
import gdb
from datetime import datetime

logfile = "crashlog.txt"
tfsbin = "tfs"

def crash(event):
    if (isinstance(event, gdb.SignalEvent) and not event.stop_signal == "SIGINT"):
        file = open(logfile, "a+")
        file.write("---------------------------------------------------\nSignal caught: " + event.stop_signal + " in " + str(datetime.now().strftime("%d/%m - %H:%M:%S")) + "\n")
        file.close()
        gdb.execute("set logging file " + logfile)
        gdb.execute("set logging on")
        gdb.execute("thread apply all bt full")
        gdb.execute("set logging redirect on")
        gdb.execute("set logging off")
        gdb.execute("kill")
        gdb.execute("quit")

gdb.events.stop.connect(crash)
gdb.execute("file " + tfsbin)
gdb.execute("set pagination off")
gdb.execute("set confirm off")
gdb.execute("run")
gdb.execute("quit")
 
Code:
#!gdb
import gdb
from datetime import datetime

logfile = "crashlog.txt"
tfsbin = "tfs"

def crash(event):
    if (isinstance(event, gdb.SignalEvent) and not event.stop_signal == "SIGINT"):
        file = open(logfile, "a+")
        file.write("---------------------------------------------------\nSignal caught: " + event.stop_signal + " in " + str(datetime.now().strftime("%d/%m - %H:%M:%S")) + "\n")
        file.close()
        gdb.execute("set logging file " + logfile)
        gdb.execute("set logging on")
        gdb.execute("thread apply all bt full")
        gdb.execute("set logging redirect on")
        gdb.execute("set logging off")
        gdb.execute("kill")
        gdb.execute("quit")

gdb.events.stop.connect(crash)
gdb.execute("file " + tfsbin)
gdb.execute("set pagination off")
gdb.execute("set confirm off")
gdb.execute("run")
gdb.execute("quit")

Thanks Matheus, can you explain a bit how to install this, and how to operate it? Thanks!
 
I mean I tried to run it, but when I close ssh, the server closes.
Make a new shell script, put "gdb -x script.py" inside it and then:
Code:
while true; do screen -LAdmS root ./NAMEOFTHESCRIPTFILE --log-file "output.txt" "error.txt"; done
 
Code:
#!gdb
import gdb
from datetime import datetime

logfile = "crashlog.txt"
tfsbin = "tfs"

def crash(event):
    if (isinstance(event, gdb.SignalEvent) and not event.stop_signal == "SIGINT"):
        file = open(logfile, "a+")
        file.write("---------------------------------------------------\nSignal caught: " + event.stop_signal + " in " + str(datetime.now().strftime("%d/%m - %H:%M:%S")) + "\n")
        file.close()
        gdb.execute("set logging file " + logfile)
        gdb.execute("set logging on")
        gdb.execute("thread apply all bt full")
        gdb.execute("set logging redirect on")
        gdb.execute("set logging off")
        gdb.execute("kill")
        gdb.execute("quit")

gdb.events.stop.connect(crash)
gdb.execute("file " + tfsbin)
gdb.execute("set pagination off")
gdb.execute("set confirm off")
gdb.execute("run")
gdb.execute("quit")

Named: tfs_startup.py

Make a new shell script, put "gdb -x script.py" inside it and then:
Code:
while true; do screen -LAdmS root ./NAMEOFTHESCRIPTFILE --log-file "output.txt" "error.txt"; done

This is the code as you said ("named control"):

Code:
gdb -x tfs_startup.py
while true; do screen -LAdmS root ./tfs_startup --log-file "output.txt" "error.txt"; done

This is the log when executing ./control:
cccfa858061f484ba99b288c906fd6fc.png



Can't make it hide on screen.
 
Nope you didn't make what I've said, you are suposed to create a bash script with
Code:
gdb -x tfs_startup.py
And then execute that bash with
Code:
while true; do screen -LAdmS root ./NAMEOFBASHSCRIPT --log-file "output.txt" "error.txt"; done
 
Nope you didn't make what I've said, you are suposed to create a bash script with
Code:
gdb -x tfs_startup.py
And then execute that bash with
Code:
while true; do screen -LAdmS root ./NAMEOFBASHSCRIPT --log-file "output.txt" "error.txt"; done

Oh, don't know what is a "bash script". Don't know what did wrong. Sry, kind new using linux yet. How to create a bash script?
 
Oh, don't know what is a "bash script". Don't know what did wrong. Sry, kind new using linux yet. How to create a bash script?
Code:
#!/bin/sh
gdb -x restarter.py

Place that in a file and do

Code:
chmod 755 filename
 
Back
Top