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
/home/your-user-name/coredumps/core-%e-sig%s-user%u-group%g-pid%p-time%t
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:
/etc/security/limits.d/core.conf
like:

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



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

(4) modify your systemd service conf
e.g., /etc/systemd/system/your-service.service
to add:
LimitCORE=infinity
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:
/home/your-user-name/coredumps/core-%e-sig%s-user%u-group%g-pid%p-time%t


References:
http://www.kibinlabs.com/re-enabling-core-dumps-redhat-7/

2 comments:

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.

Ashwani Jha said...

thank you so much for all