Debian Codegraph @

utils/crossloop.web.in

raw
1 #!/bin/bash
2 #
3 # This is a replacement for the crosserv.pl perl script.,
4 # No point in using perl for such a simple task.
5 # This script 'archives' relevent crash information in some
6 # directory, and sends a mail message informing people of
7 # the crash. The mail message includes the backtrace info.
8 # This was originally written by Bob Tanner, modified by Mark Wedel
9
10 # NOTE: Before using this script, some of the variables at the top
11 # will need to be changed. Also note that make install will not
12 # overwrite this file if it already exists.
13
14 # Note2: This script uses $HOME/.gdbweb as the script used to
15 # feed to gdb. This file should be like:
16 # echo \n(gdb) Executing command "bt full":\n\n
17 # bt full
18 # echo \n(gdb) Executing command "up" (20 times):\n\n
19 # up
20 # up (repeat 18 more times)
21 #
22
23 # due to variable substitution, we need all of this for it to
24 # work.
25 prefix="@prefix@"
26 exec_prefix="@exec_prefix@"
27 bindir="@bindir@"
28
29 CROSSFIRE="$bindir/crossfire-server"
30
31 # This can include multiple people, just seperate them by commas.
32 MAILTO="master@hugin"
33
34 # This is the program used to send out the mail message. It needs
35 # to support the -s (subject) option. On SysV systems, this may be
36 # /usr/ucb/mail.
37 MAIL=/usr/bin/Mail
38
39 # URL that contains the publicly available crash information.
40 # Thi is only used in the mail message that is sent out to make it
41 # easier for people to go to the web site.
42 URL="http://www.metalforge.org/core/"
43
44 MAXRESTART=500
45
46 # This is the publicly available directory that will contain the log
47 # and core files.
48 HTMLDIR="$HOME/public_html"
49
50 # This is where the source resides on the server. This is used to
51 # get better information on backtraces.
52 # This should be independent of other commands run from this file.
53 # So the use of cd to get the the source directory should not conflict with anything else.
54 SRCDIR=`cd @top_srcdir@; pwd`;
55 # And then we trim off the newline from pwd, since we do not need it.
56 chomp($SRCDIR);
57
58
59 ulimit -c unlimited
60
61 logcount=0
62
63 if [ ! -d $HTMLDIR ]; then
64 echo "$HTMLDIR does not exist. Aborting."
65 exit 1
66 fi
67
68
69 while [ ! "$logcount"x = "$MAXRESTART"x ]; do
70 echo "Starting Crossfire `date` for the $logcount time..." 1>$HTMLDIR/server.$$.$logcount.log 2>&1
71 $CROSSFIRE -d 2>>$HTMLDIR/server.$$.$logcount.log 1>&2
72 if [ -f core ] ; then
73
74 echo "<html><pre>" > $HTMLDIR/backtrace.$$.$logcount.html
75 /usr/bin/gdb -batch -d $SRCDIR -x $HOME/.gdbweb $CROSSFIRE core >> $HTMLDIR/backtrace.$$.$logcount.html
76 if [ $? -ne 0 ]; then
77 echo "gdb failed for some reaons." >> $HTMLDIR/backtrace.$$.$logcount.html
78 fi
79 echo "</pre></html>" >> $HTMLDIR/backtrace.$$.$logcount.html
80
81
82 mv core $HTMLDIR/core.$$.$logcount
83 if [ $? -ne 0 ]; then
84 echo "Could not move core file."
85 break
86 fi
87
88 @GZIP@ -9 $HTMLDIR/core.$$.$logcount &
89 @GZIP@ -9 $HTMLDIR/server.$$.$logcount.log &
90 /bin/chmod 644 $HTMLDIR/core*.gz
91
92 echo "Crossfired crashed at `date`. Crash instance is $logcount." > /tmp/crossloop.web.$$
93 echo "The core files and server log can be found at" >> /tmp/crossloop.web.$$
94 echo "$URL/backtrace.$$.$logcount.html" >> /tmp/crossloop.web.$$
95 echo "$URL/core.$$.$logcount.gz" >> /tmp/crossloop.web.$$
96 echo "$URL/server.$$.$logcount.log.gz" >> /tmp/crossloop.web.$$
97
98 cat /tmp/crossloop.web.$$ $HTMLDIR/backtrace.$$.$logcount.html | $MAIL -s "Crossfire crashed." $MAILTO
99 @RM@ /tmp/crossloop.web.$$
100 else
101 # may or may not want to keep the old one around.
102 #@RM@ $HTMLDIR/backtrace.$$.$logcount.html
103 # Need some statement here for the else/fi to work.
104 /bin/false
105 fi
106 logcount=`expr $logcount + 1`
107 sleep 10s
108 done