Enable Linux Core Dump

0
3839

Enable Linux Core Dumps One of our applications (Freeswitch) just randomly crashed for no apparent reason and didn’t write anything to it’s log files. The service we’re trialling is currently in Beta so there’s room to muck about and do some diagnostics. I want to make the kernel dump a core file whenever Freeswitch dies, in case it happens again, so that we have some stuff to work with after the fact. It’ll also shut up my QA manager.

Check The Current Linux Core Dump Limits

ulimit is used to specify the maximum size of generated coredumps, this is to stop apps chewing up a million GB of RAM and then blowing your disk up, by default it’s a 0, which means nothing gets written to disk and no dump is created!

Change The Linux Core Dump Limits To Something Awesome

To set the size limit of the linux core files to 75000 bytes, you can do something like this

but I’m a maverick, this does exactly what you think it does

Enable Linux Core Dump For Application Crashes And Segfaults And Things

Ok, so we want this to persist across reboots so that basically means we have to stick the ulimit command in /etc/profile, i’m putting this at the bottom of mine:

this will stop anything weird getting spat out to the screen and nicely tells us that it’s core file stuff.

For our next trick we’ll set some sysctl flags so in /etc/sysctl.conf add

this basically says when the application crashes create a coredump file in /tmp with a useful name pattern

super usefuls. Then run sysctl -p so it takes effect yo!

Enabling Linux Core Dump For All Apps

Now here’s the last part. When you want an application to core dump you create an environment variable, before you start it, telling the kernel to sort itself out and get ready to dump, if you want all apps on the server to generate core dumps then you’re going to want to specify this variable somewhere near the top of the process chain. The best place for this on a redhat style box is /etc/sysconfig/init, so stick the following in that file

now might be an idea to reboot to force it to be set across all applications and things

Enabling Linux Core Dumps For A Specific Application

This is the slightly less rebooty version of the above. Rather than force the environment variable to be loaded when the box starts, we just stick it in the init script for the deamon, and then restart the daemon.

In /etc/init.d/functions the RedHat guys have already stuck in

So we need to make sure we put our DEAMON_COREFILE_LIMIT above that. Simples. In our case it’s in /etc/init.d/freeswitch with

Distros That Aren’t RedHat

DAEMON_COREFILE_LIMIT is a RedHatism. If you’re running something cool, like Ubuntu, you’ll want to use

instead.

Testing Core Dumps

This is EASY, we just start the deamon, send a segfault signal, look in the right place!!

Now you give this file to your developers and take a bow!