2 # Script to save core files, to be run from post_crash_dump_hook
3 # Written by Markus Armbruster, 2008-2012
4 # This script is in the public domain.
6 # Use: edit configuration variables below to taste, then set
7 # post_crash_dump_hook = /wherever/savecore
8 # in econfig. Make sure to run the server with core dumps enabled
9 # (ulimit -c unlimited).
11 # Rules when running as post_crash_dump_hook:
12 # Data directory is working directory.
13 # stdin, stdout, stderr are redirected to /dev/null, except in debug
18 # How your system names core files
20 # This is a pattern rather than a name, because modern kernels can put
21 # fancy stuff in the name we can't always predict.
23 #core_pattern=emp_server.core
26 # Where to save core dumps
28 # If you leave cores in the data directory, backup scripts may pick
29 # them up, which is probably not what you want.
30 core_dir=../core-dumps
32 # Minimum free disk space for saving core dumps, in KiB
35 # Whom to send mail (leave empty to not send any)
38 # Program to send mail
41 # End of configuration
49 then msg="Core dump $saved_core saved."
50 else msg="Could not save core dump."
52 echo $msg | $mailx -s "emp_server dumped core in $PWD" "$privlog"
55 test -n "$privlog" && trap 'alert_deity' EXIT
57 core_name=`ls -td $core_pattern | head -n 1`
60 tstamp=`/bin/date +%Y-%m-%d-%H:%M`
61 saved_core=$core_dir/core-$tstamp
64 if [ `df -kP $core_dir | awk 'NR!=1 { print $4 }'` -lt "$space_low" ]
65 then rm -f $core_name; exit
68 mv -f $core_name $saved_core