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. Modern user space
22 # can squirrel away core dumps in fancy places; you may need to switch
23 # that off for this insufficiently fancy script to work.
25 #core_pattern=emp_server.core
28 # Where to save core dumps
30 # If you leave cores in the data directory, backup scripts may pick
31 # them up, which is probably not what you want.
32 core_dir=../core-dumps
34 # Minimum free disk space for saving core dumps, in KiB
37 # Whom to send mail (leave empty to not send any)
40 # Program to send mail
43 # End of configuration
52 then msg="Core dump $saved_core saved."
54 then msg="Could not save core dump $core_name."
55 else msg="Could not find core dump to save."
57 echo "$msg" | $mailx -s "emp_server dumped core in $PWD" "$privlog"
60 test -n "$privlog" && trap 'alert_deity' EXIT
62 core_name=`ls -td $core_pattern 2>/dev/null | head -n 1`
65 tstamp=`/bin/date +%Y-%m-%d-%H:%M`
66 saved_core=$core_dir/core-$tstamp
69 if [ `df -kP $core_dir | awk 'NR!=1 { print $4 }'` -lt "$space_low" ]
70 then rm -f "$core_name"; exit
73 mv -f "$core_name" $saved_core