Login
User Name:

Password:



Register

Forgot your password?
A Bash Startup Script
Feb 7, 2026 3:49 pm
By eldhamud
Force Skills
Jan 1, 2026 3:58 pm
By Elwood
Overland with Bitmaps
Jul 4, 2025 11:57 pm
By Samson
void nanny_get_new_race -- comm.c
Mar 13, 2025 7:08 am
By Elwood
IPv6
Jan 25, 2025 10:45 pm
By Samson
SWFotEFUSS 1.5.3
Author: Various
Submitted by: Samson
SWRFUSS 1.4.3
Author: Various
Submitted by: Samson
SmaugFUSS 1.9.8
Author: Various
Submitted by: Samson
AFKMud 2.5.2
Author: AFKMud Team
Submitted by: Samson
SmaugFUSS 1.9.7
Author: Various
Submitted by: Samson
Users Online
Anthropic, Bing, Sogou, AhrefsBot

Members: 0
Guests: 35
Stats
Files
Topics
Posts
Members
Newest Member
507
3,814
19,734
597
MayraPdj03

» SmaugMuds » Codebases » SmaugFUSS » A Bash Startup Script
Forum Rules | Mark all | Recent Posts

A Bash Startup Script
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 Feb 7, 2026 3:49 pm   
Go to the top of the page
Go to the bottom of the page

eldhamud
Fledgling
GroupMembers
Posts47
JoinedFeb 16, 2006

 
I dont like tch, so here is a bash script, it also does some log management, keeping the last 3 logs only.

#!/bin/bash

# Set the port number (default 4000 or from first argument)
port=4000
if [ -n "$1" ]; then
    port="$1"
fi

# Change to area directory
cd ../area || { echo "Failed to change directory to ../area"; exit 1; }

# Set limits, needed in ubuntu to get core files, also need to give users permissions to /var/lib/systemd/coredump/ to write dumps to

ulimit -c unlimited

# Remove shutdown.txt if it exists
[ -e shutdown.txt ] && rm -f shutdown.txt

while true; do
    # Find a free log file
    index=1000
    while true; do
        logfile="../log/${index}.log"
        if [ ! -e "$logfile" ]; then
            break
        fi
        ((index++))
    done

    # Record starting time
    date > "$logfile"
    date > ../area/boot.txt

    # Check if SMAUG is already running on the port
    matches=$(netstat -an | grep ":$port " | grep -c LISTEN)
    if [ "$matches" -ge 1 ]; then
        echo "Port $port is already in use."
        exit 0
    fi

    # Run SMAUG
    ../src/smaug "$port" &> "$logfile"

    # Keep only the last 3 log files, delete older ones
    logdir="../log"
    if [ -d "$logdir" ]; then
        # Find all log files sorted by modification time, oldest first
        files=($(ls -1tr "$logdir"/*.log 2>/dev/null))
        count=${#files[@]}
        if [ "$count" -gt 3 ]; then
            # Delete all but the last 3
            for ((i=0; i<count-3; i++)); do
                rm -f "${files[i]}"
            done
        fi
    fi

    # Restart logic: exit if shutdown.txt exists
    if [ -e shutdown.txt ]; then
        rm -f shutdown.txt
        exit 0
    fi

    # Give old connections a chance to die
    sleep 15
done


Pages:<< prev 1 next >>