Thursday, June 9, 2016

Enable core dumps for systemd services on CentOS 7

Core dumps are very useful to C++ programs to debug critical crashes like segfault, etc.

How to enable core dumps for systemd services on CentOS 7?

(1) change the core_pattern to some place you could write to
$ cat /proc/sys/kernel/core_pattern
Note: your-user-name is the user name you are using to run your program which would crash to generate a core dump.

(2) create a new file:

*       hard        core        unlimited
*       soft        core        unlimited
to enable core dumps for all users

(3) modify /etc/systemd/system.conf
to add:

(4) modify your systemd service conf
e.g., /etc/systemd/system/your-service.service
to add:
in the "[Service]" section.

(5) reload the new systemd conf and restart your service
systemctl daemon-reexec
systemctl stop your-service
systemctl start your-service
(6) how to test it
You could kill your service process by sending signal 11 (SIGSEGV) to your process. By right, you should see a new core dump at:



ari mattila said...

I looked this for some time, many thanks.

one note to point one, echo the path and or pattern to core_pattern file.
e.g cat/var/crash/core > /proc/sys/kernel/core_pattern

Anonymous said...

Thank you so much! It is hard to find info on how to get systemd processes to create a core on CentOS 7.