Debian Codegraph @

utils/crossloop.in

raw
1 #!/bin/sh
2 # crossloop -- restart crossfire-server in case of a crash
3
4 # You should not edit this script! Instead, place any overrides into one of
5 # the configuration files.
6
7 # Set paths that are determined by the build system.
8 prefix="@prefix@"
9 exec_prefix="@exec_prefix@"
10
11 # Read configuration files.
12 for config_file in "@sysconfdir@/crossfire/crossloop.conf"; do
13 if [ -r ${config_file} ]; then
14 . ${config_file} && echo "===>>> Loaded '${config_file}'"
15 fi
16 done
17
18 #### CONFIGURATION ####
19
20 # Full path to server binary.
21 CF_BIN=${CF_BIN:-"@bindir@/crossfire-server"}
22
23 # Additional flags to pass to the server.
24 CF_FLAGS=${CF_FLAGS:-"-d"}
25
26 # Directory to use for storing temporary runtime files. It is created if it
27 # does not exist. It should be dedicated to Crossfire, because it is saved
28 # in the event of a server crash.
29 CF_TMP=${CF_TMP:-"/tmp/crossfire"}
30
31 # Path to server log (default "$CF_TMP/crossfire.log").
32 CF_LOG=${CF_LOG:-"${CF_TMP}/crossfire.log"}
33
34 # Maximum number of restarts (set to zero to loop infinitely, default 100).
35 MAX_RESTART=${MAX_RESTART:-"100"}
36
37 # Directory for saving crash data.
38 CRASH_DIR=${CRASH_DIR:-"`dirname ${CF_TMP}`"}
39
40 # Send mail to server admins in case of a crash (comment out to disable).
41 #CRASH_MAIL="[email protected]"
42
43 #### END OF CONFIGURATION ####
44
45 # The current generation of the server.
46 generation=1
47
48 while [ ${MAX_RESTART} -ne ${generation} ]; do
49 # Create folder to store temporary files if it doesn't exist.
50 if [ ! -d ${CF_TMP} ]; then
51 mkdir ${CF_TMP}
52 chmod 700 ${CF_TMP}
53 fi
54
55 # Change to the ${CF_TMP} directory and start server.
56 cd ${CF_TMP}
57 echo "===>>> Starting server (generation ${generation})..."
58
59 ${CF_BIN} ${CF_FLAGS} -tmpdir "${CF_TMP}" -log "${CF_LOG}"
60
61 # If the server crashed and CRASH_DIR is set, save CF_TMP.
62 if [ ${?} -ne 0 -a -n "${CRASH_DIR}" ]; then
63 crash_dump="${CRASH_DIR}/crossfire-`date +%Y-%m-%d-%H:%M`.crash"
64 mv ${CF_TMP} ${crash_dump}
65 core_files=`ls ${crash_dump}/*core*`
66 dumpfile="${crash_dump}/crash.log"
67 cat << EOF > $dumpfile
68 Crossfire has terminated unexpectedly. Information about this crash is saved
69 in '${crash_dump}' on `hostname`.
70
71 `uname -a`
72
73 The following core dumps were found:
74
75 ${core_files}
76
77 The following backtrace was generated by GDB:
78
79 `gdb ${CF_BIN} ${core_files} -batch`
80
81 If this crash occurs frequently or can be reliably reproduced, please file a
82 bug report with the full contents of this crash report.
83 EOF
84
85 if [ -n "${CRASH_MAIL}" ]; then
86 mail -s "Crossfire crash on `hostname`" "${CRASH_MAIL}" < $dumpfile
87 fi
88 echo "===>>> Crash info saved in $dumpfile"
89 fi
90
91 echo "===>>> Restarting server (type CTRL-C to quit)..."
92 # Increment server generation.
93 generation=`expr ${generation} + 1`
94
95 # Wait for 10 seconds before restarting again.
96 sleep 10
97 done