@@ -267,73 +267,117 @@ $3 = std::vector of length 11, capacity 16 = {{static NPos = 1844674407370955161
267
267
268
268
### Core Dump <a id =" development-debug-core-dump " ></a >
269
269
270
- When the Icinga 2 daemon crashes with a ` SIGSEGV ` signal
271
- a core dump file should be written. This will help
272
- developers to analyze and fix the problem.
270
+ When the Icinga 2 daemon is terminated by signals ` SIGSEGV ` or ` SIGABRT ` , a core
271
+ dump file should be written. This will help developers to analyze and fix the
272
+ problem.
273
273
274
- #### Core Dump File Size Limit <a id =" development-debug-core-dump-limit " ></a >
274
+ #### Core Dump Kernel Pattern <a id =" development-debug-core-dump-format " ></a >
275
275
276
- This requires setting the core dump file size to ` unlimited ` .
276
+ Core dumps are generated according to the format specified in
277
+ ` /proc/sys/kernel/core_pattern ` . This can either be a path relative to the
278
+ directory the program was started in, an absolute path or a pipe to a different
279
+ program.
277
280
281
+ For more information see the [ core(5)] ( https://man7.org/linux/man-pages/man5/core.5.html ) man page.
278
282
279
- ##### Systemd
283
+ #### Systemd Coredumpctl < a id = " development-debug-core-dump-systemd " ></ a >
280
284
285
+ Most distributions offer systemd's coredumpctl either by default or as a package.
286
+ Distributions that offer it by default include RHEL and SLES, on others like
287
+ Debian or Ubuntu it can be installed via the ` systemd-coredump ` package.
288
+ When set up correctly, ` core_pattern ` will look something like this:
289
+ ```
290
+ # cat /proc/sys/kernel/core_pattern
291
+ |/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h`
281
292
```
282
- systemctl edit icinga2.service
283
293
284
- [Service]
285
- ...
286
- LimitCORE=infinity
294
+ You can look at the generated core dumps with the ` coredumpctl list ` command.
295
+ You can show information, including a stack-trace using
296
+ ` coredumpctl show icinga2 -1 ` and retrieve the actual core-dump file with
297
+ ` coredumpctl dump icinga2 -1 --output <file> ` .
287
298
288
- systemctl daemon-reload
299
+ #### Ubuntu Apport < a id = " development-debug-core-dump-apport " ></ a >
289
300
290
- systemctl restart icinga2
301
+ Ubuntu uses their own application ` apport ` to record core dumps. When it is
302
+ enabled your ` core_pattern ` will look like this:
303
+ ```
304
+ # cat /proc/sys/kernel/core_pattern
305
+ |/usr/share/apport/apport -p%p -s%s -c%c -d%d -P%P -u%u -g%g -- %E
291
306
```
292
307
293
- ##### Init Script
308
+ Apport is unsuitable for development work, because by default it only works
309
+ with Ubuntu packages and it has a rather complicated interface for retrieving
310
+ the core dump.
294
311
312
+ To set it up to work with unpackaged programs, add the following (create the
313
+ file if it doesn't exist) to ` /etc/apport/settings ` :
295
314
```
296
- vim /etc/init.d/icinga2
297
- ...
298
- ulimit -c unlimited
299
-
300
- service icinga2 restart
315
+ [main]
316
+ unpackaged=true
317
+ ```
318
+ and restart Apport:
319
+ ```
320
+ systemctl restart apport.service
301
321
```
302
322
303
- ##### Verify
323
+ When the program crashes you can then find an Apport crash report in ` /var/crash/ `
324
+ that you can read with the interactive ` apport-cli ` command. To extract the core
325
+ dump you run ` apport-unpack /var/crash/<crash-file> <output-dir> ` which then
326
+ saves a ` <outputdir>/CoreDump ` file that contains the actual core dump.
304
327
305
- Verify that the Icinga 2 process core file size limit is set to ` unlimited ` .
328
+ Unless you rely on Apport for some other workflow, systemd's coredumpctl is a
329
+ much better option and is available on Ubuntu in the ` systemd-coredump ` package
330
+ that can replace Apport on your system with no further setup required.
306
331
307
- ```
308
- for pid in $(pidof icinga2); do cat /proc/$pid/limits; done
332
+ #### Directly to a File <a id =" development-debug-core-dump-direct " ></a >
309
333
310
- ...
311
- Max core file size unlimited unlimited bytes
334
+ If coredumpctl is not available, simply writing the core dump directly to a file
335
+ is also sufficient. You can set up your ` core_pattern ` to write a file to a
336
+ suitable path:
337
+
338
+ ``` bash
339
+ sysctl -w kernel.core_pattern=/var/lib/cores/core.%e.%p.%h.%t
340
+ install -m 1777 -d /var/lib/cores
312
341
```
313
342
343
+ If you want to make this setting permanent you can also add a file to
344
+ ` /etc/sysctl.d ` , named something like ` 80-coredumps.conf ` :
345
+ ```
346
+ kernel.core_pattern = /var/lib/cores/core.%e.%p.%h.%t
347
+ ```
314
348
315
- #### Core Dump Kernel Format <a id =" development-debug-core-dump-format " ></a >
349
+ This will create core dump files in ` /var/lib/cores ` where ` %e ` is the truncated
350
+ name of the program, ` %p ` is the programs PID, ` %h ` is the hostname, and ` %t ` a
351
+ timestamp.
316
352
317
- The Icinga 2 daemon runs with the SUID bit set. Therefore you need
318
- to explicitly enable core dumps for SUID on Linux.
353
+ Note that unlike the other methods this requires the core size limit to be set
354
+ for the process. When starting Icinga 2 via systemd you can set it to unlimited
355
+ by adding the following to ` /etc/systemd/system/icinga2.service.d/limits.conf ` :
356
+ ```
357
+ [Service]
358
+ LimitCORE=infinity
359
+ ```
319
360
361
+ When using an init script or starting manually you need to run ` ulimit -c unlimited `
362
+ before starting the program:
320
363
``` bash
321
- sysctl -w fs.suid_dumpable=2
364
+ ulimit -c unlimited
365
+ ./icinga2 daemon
322
366
```
323
367
324
- Adjust the coredump kernel format and file location on Linux:
325
-
368
+ To verify that the limit has been set to ` unlimited ` run the following:
326
369
``` bash
327
- sysctl -w kernel.core_pattern=/var/lib/cores/core.%e.%p
328
-
329
- install -m 1777 -d /var/lib/cores
370
+ for pid in $( pidof icinga2) ; do cat /proc/$pid /limits; done
371
+ ```
372
+ And look for the line:
373
+ ```
374
+ Max core file size unlimited unlimited bytes
330
375
```
331
376
332
- MacOS:
377
+ #### MacOS < a id = " development-debug-core-dump-macos " ></ a >
333
378
334
379
``` bash
335
380
sysctl -w kern.corefile=/cores/core.%P
336
-
337
381
chmod 777 /cores
338
382
```
339
383
0 commit comments