File: crossloop

package info (click to toggle)
crossfire 1.75.0-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,168 kB
  • sloc: ansic: 83,169; sh: 4,659; perl: 1,736; lex: 1,443; makefile: 1,199; python: 43
file content (97 lines) | stat: -rw-r--r-- 2,920 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/sh
# crossloop -- restart crossfire-server in case of a crash

# You should not edit this script! Instead, place any overrides into one of
# the configuration files.

# Set paths that are determined by the build system.
prefix="/opt/invidious"
exec_prefix="${prefix}"

# Read configuration files.
for config_file in "${prefix}/etc/crossfire/crossloop.conf"; do
    if [ -r ${config_file} ]; then
        . ${config_file} && echo "===>>> Loaded '${config_file}'"
    fi
done

#### CONFIGURATION ####

# Full path to server binary.
CF_BIN=${CF_BIN:-"${exec_prefix}/bin/crossfire-server"}

# Additional flags to pass to the server.
CF_FLAGS=${CF_FLAGS:-"-d"}

# Directory to use for storing temporary runtime files. It is created if it
# does not exist. It should be dedicated to Crossfire, because it is saved
# in the event of a server crash.
CF_TMP=${CF_TMP:-"/tmp/crossfire"}

# Path to server log (default "$CF_TMP/crossfire.log").
CF_LOG=${CF_LOG:-"${CF_TMP}/crossfire.log"}

# Maximum number of restarts (set to zero to loop infinitely, default 100).
MAX_RESTART=${MAX_RESTART:-"100"}

# Directory for saving crash data.
CRASH_DIR=${CRASH_DIR:-"`dirname ${CF_TMP}`"}

# Send mail to server admins in case of a crash (comment out to disable).
#CRASH_MAIL="yourname@example.com"

#### END OF CONFIGURATION ####

# The current generation of the server.
generation=1

while [ ${MAX_RESTART} -ne ${generation} ]; do
    # Create folder to store temporary files if it doesn't exist.
    if [ ! -d ${CF_TMP} ]; then
        mkdir ${CF_TMP}
        chmod 700 ${CF_TMP}
    fi

    # Change to the ${CF_TMP} directory and start server.
    cd ${CF_TMP}
    echo "===>>> Starting server (generation ${generation})..."

    ${CF_BIN} ${CF_FLAGS} -tmpdir "${CF_TMP}" -log "${CF_LOG}"

    # If the server crashed and CRASH_DIR is set, save CF_TMP.
    if [ ${?} -ne 0 -a -n "${CRASH_DIR}" ]; then
        crash_dump="${CRASH_DIR}/crossfire-`date +%Y-%m-%d-%H:%M`.crash"
        mv ${CF_TMP} ${crash_dump}
        core_files=`ls ${crash_dump}/*core*`
        dumpfile="${crash_dump}/crash.log"
        cat << EOF > $dumpfile
Crossfire has terminated unexpectedly. Information about this crash is saved
in '${crash_dump}' on `hostname`.

`uname -a`

The following core dumps were found:

${core_files}

The following backtrace was generated by GDB:

`gdb ${CF_BIN} ${core_files} -batch`

If this crash occurs frequently or can be reliably reproduced, please file a
bug report with the full contents of this crash report.
EOF

        if [ -n "${CRASH_MAIL}" ]; then
            mail -s "Crossfire crash on `hostname`" "${CRASH_MAIL}" < $dumpfile
        fi
        echo "===>>> Crash info saved in $dumpfile"
    fi

    echo "===>>> Restarting server (type CTRL-C to quit)..."
    # Increment server generation.
    generation=`expr ${generation} + 1`

    # Wait for 10 seconds before restarting again.
    sleep 10
done