03 Nov, 2014, koqlb wrote in the 1st comment:
Votes: 0
Okay, so I've tried both versions of MUDcheck.pl and no luck. (v1.1 was VERY hard to find on google, but I finally got it)
I'm not good with perl, but I DO know that it's worked for me before, and I've looked up enough to the point that I've managed to get it to change the filename of the log file it's supposed to create. I'd MUCH rather have a bash shell script that could check to see if the MUD is running, then run it if necessary. Mainly, because I want to put this on my crontab to keep it up at all times because I can't always be on or connect to the server to restart the MUD should it crash.

Unfortunately, i can't get the frickin' thing to write a log file… I believe the problem is somewhere in the restart_mud function, but as i said i don't know. I'm trying to run my runsv1.pl script from my home directory, as everything SHOULD be directed correctly. But I'm getting this error when I run it:
Connection to localhost on port 5680 failed or timed out after 60 seconds!
Attempting to restart the mud on Mon Nov 3 19:51:13 2014…
sh: 1: cannot create ../log/110314.1951: Directory nonexistent
sh: 2: .log: not found

I get a Directory nonexistent or no such file or directory error with each version of mudcheck…
How do I get it to create the logfile so it can output the mud data to it?

I get a Directory nonexistent or no such file or directory error with each version of mudcheck…
How do I get it to create the logfile so it can output the mud data to it?
[bNOW: Be warned, below is the ENTIRE runsv1.pl file. Sorry it's so much to look at:[/b]

[code]#!/usr/bin/perl
#########################################################################
# mudcheck.pl Version 1.1 #
# Created: Jun 28, 1997 Jared Proudfoot #
# Last Modified: Jun 28, 1997 jproudfo@footprints.net #
#########################################################################
# README #
# #
# This is a pretty simple script that checks to see if a mud is running #
# properly. Be sure to change the 'important vars' section. The best #
# idea is to run this script from cron every couple of minutes… That #
# way you can be sure that it stays running. #
#########################################################################
# CHANGES AND HISTORY #
# #
# v 1.0, Jun 28, 1997 Created. Seems to work fine now. #
# v 1.1, Feb 11, 2005 Zz - changed log date format, added link #
#########################################################################
#########################################################################
# Define the important vars #
# #
# Define the host and port number where the mud resides. #

$server = "localhost";
$port = "5680";
$infoport = "5681";

# $string is the string of characters we will look for upon connecting. #
# If we connect, but don't see this string, we will assume the mud #
# isn't responding (locked up?) and we'll restart it. The string #
# *must* be on the first line after connect.

# You may enter this as a regexp if you wish. #

$replyString = "^\n";

# How long do we wait before we connect timeout (in seconds)? #

$timeOut = "60";

# What to execute if we need to restart the mud. Please include the #
# FULL path. #
$mudpath = "sv3";

$exec = "../src/subvis";

# Path where you want the mud logs to be kept.

$logdir = "../log";

# Path where we should start the mud from. #
$startPath = "/sv3/area";

# That's it. You shouldn't need to change anything after this line. #
#########################################################################

# What do we need to use?
use Socket;
require 5.003;



#########################################################################
# Main #
#########################################################################

if (&connect_server == 0) {
# If we couldn't connect, try and restart. #
print ("Connection to $server on port $port failed or timed out after $timeOut seconds!\n");
$time = (scalar localtime);
print ("Attempting to restart the mud on $time…\n");
# Restart the mud #
&restart_mud;
}
else {
# We connected, but is it working properly? #
$readline = (&gl);
if ($readline =~ /$replyString/) {
# We found what we were looking for, so exit #
# properly. #
&disconnect_server;
exit 1;
}
# After all those searches, we didn't find anything. The mud #
# must be locked up. Lets kill and restart it. #
&disconnect_server;
print ("The connection was sucessful, but it doesn't seem to be responding\n");
$time = (scalar localtime);
print ("Attempting to restart the mud on $time…\n");
system("killall $exec");
&restart_mud;
}




#########################################################################
# Subroutines #
#########################################################################


sub connect_server {
# Connect to the server #
my ($iaddr, $paddr, $proto);
$iaddr = inet_aton ($server)
or die ("ERROR: No host: $server!\n");
$paddr = sockaddr_in ($port, $iaddr);
$proto = getprotobyname('tcp');
socket (SOCK, PF_INET, SOCK_STREAM, $proto)
or die ("ERROR: Socket error $!\n");
alarm ($timeOut);
if (connect (SOCK, $paddr)) {;
alarm (0);
return 1;
}
else {
return 0;
}
}

sub disconnect_server {
# Disconnect from the server #
close (SOCK);
return;
}

sub sl {
# Send a line #
my ($line)=@_;
print SOCK ("$line")
or die ("ERROR: Error writing to server: $!\n");
select SOCK;
$|=1;
select STDOUT;
$|=1;
return;
}

sub gl {
# Get a line #
my ($buffer, @reply);
$buffer=(<SOCK>);
# (@reply) = split (/\s/, $buffer);
# return (@reply);
return ($buffer);
}

sub restart_mud {
# Restart the mud #
#$NOW = mo/date/yr.24hrtime;

$NOW = `date +%m%d%y.%H%M`;
$logfile = $NOW . ".log";
chdir $startPath;

unlink "$logdir/current.log";
symlink "$logdir/$logfile", "$logdir/current.log";

system ("$exec -p $port -i $infoport > $logdir/$logfile 2>&1 &");

return;
}
[/code]
04 Nov, 2014, koqlb wrote in the 2nd comment:
Votes: 0
Nevermind. Figured out a bash cron script. I'll upload it.
04 Nov, 2014, alteraeon wrote in the 3rd comment:
Votes: 0
I don't think anyone actually uses cron for this purpose. Everyone I've seen just runs the mud server from an infinite loop bash script:

#!/bin/sh

while true; do
./mud_executable args
sleep 4
done

Just log in, run the script in the background, and log out. It'll keep running until you kill it or the server reboots, and the game will never be down more than a few seconds if it crashes.
04 Nov, 2014, quixadhal wrote in the 4th comment:
Votes: 0
I use two files for my own DikuMUD.

A bash script that loops and handles logfile management, unless you exit with a shutdown commnad, and an /etc/init.d script to start things up when the machine boots.

#!/bin/bash
# 42 is our magic number for not rebooting,
# otherwise we assume it crashed or we said reboot.

PORT=3000
MUDDIR=/home/wiley
PATH=$MUDDIR/bin:/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=$MUDDIR/bin/wileymud
SCRIPT=$MUDDIR/bin/wileyloop
PIDFILE=$MUDDIR/etc/wileymud.pid
STARTDIR=$MUDDIR/bin

cd $STARTDIR
while [ -x $DAEMON ]; do
LOGFILE=`/bin/date "+$MUDDIR/lib/log/runlog.%y%m%d-%H%M%S"`
touch $LOGFILE
chmod 640 $LOGFILE
export MALLOC_CHECK=2
$DAEMON -P $PIDFILE -L $LOGFILE $PORT
STATUS=$?
rm -f $PIDFILE
sync
bzip2 -9q $LOGFILE
sync
if [ $STATUS = 42 ]; then
exit
fi
echo "Status was $STATUS"
sleep 120
done


#!/bin/sh
#
### BEGIN INIT INFO
# Provides: wiley
# Required-Start: $network $local_fs $remote_fs $syslog $named $time postgresql
# Required-Stop: $network $local_fs $remote_fs $syslog $named $time postgresql
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: init-Script for WileyMUD
### END INIT INFO
#

PORT=3000
MUDDIR=/home/wiley
PATH=$MUDDIR/bin:/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=$MUDDIR/bin/wileymud
SCRIPT=$MUDDIR/bin/wileyloop
PIDFILE=$MUDDIR/etc/wileymud.pid
STARTDIR=$MUDDIR/bin
LOGFILE=`/bin/date "+$MUDDIR/lib/log/runlog.%y%m%d-%H%M%S"`

test -x $DAEMON || exit 0

case "$1" in
start)
echo -n "Starting MUD Server: WileyMUD"
if start-stop-daemon –quiet –stop –signal 0 –pidfile $PIDFILE –name wileymud –user wiley
then
echo " already running."
exit
fi
/sbin/start-stop-daemon –start –quiet –chuid wiley:users –chdir $STARTDIR –background –pidfile $PIDFILE –exec $SCRIPT – -P $PIDFILE -L $LOGFILE $PORT
echo "."
;;
stop)
echo -n "Stopping MUD Server: WileyMUD"
if start-stop-daemon –quiet –stop –signal 0 –pidfile $PIDFILE –name wileymud –user wiley
then
PID=`cat $PIDFILE`
start-stop-daemon –quiet –stop –signal INT –user wiley –exec $DAEMON –pidfile $PIDFILE –name wileymud
# Now we wait for it to die
while kill -0 $PID 2>/dev/null; do sleep 1; done
rm -f $PIDFILE
echo "."
else
echo " not running.";
fi
;;
restart)
$0 stop
$0 start
;;
status)
if [ ! -f $PIDFILE ]; then
echo "No PID file, game may be down"
ps auxww | grep wiley | grep -v grep
else
ps auxww | grep `cat $PIDFILE` | grep -v grep
fi
;;
*)
echo "Usage: /etc/init.d/wiley {start|stop|restart|status}"
exit 1
esac

exit 0
0.0/4