Skip to content

Commit 33824c2

Browse files
authored
Merge pull request #10418 from Icinga/jschmidt/doc-impr-unity-builds-core-dumps
Improvements to core dumps section in developer documentation (and some smaller stuff)
2 parents e34f45c + 88b2831 commit 33824c2

File tree

2 files changed

+102
-44
lines changed

2 files changed

+102
-44
lines changed

doc/19-technical-concepts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ You can read the full story [here](https://github.com/Icinga/icinga2/issues/7309
204204

205205
With 2.11 you'll now see 3 processes:
206206

207-
- The umbrella process which takes care about signal handling and process spawning/stopping
207+
- The umbrella process which takes care of signal handling and process spawning/stopping
208208
- The main process with the check scheduler, notifications, etc.
209209
- The execution helper process
210210

doc/21-development.md

Lines changed: 101 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -267,73 +267,130 @@ $3 = std::vector of length 11, capacity 16 = {{static NPos = 1844674407370955161
267267

268268
### Core Dump <a id="development-debug-core-dump"></a>
269269

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 `SIGSEGV` or `SIGABRT`, a core dump file
271+
should be written. This will help developers to analyze and fix the problem.
273272

274-
#### Core Dump File Size Limit <a id="development-debug-core-dump-limit"></a>
273+
#### Core Dump Kernel Pattern <a id="development-debug-core-dump-format"></a>
275274

276-
This requires setting the core dump file size to `unlimited`.
275+
Core dumps are generated according to the format specified in
276+
`/proc/sys/kernel/core_pattern`. This can either be a path relative to the
277+
directory the program was started in, an absolute path or a pipe to a different
278+
program.
277279

280+
For more information see the [core(5)](https://man7.org/linux/man-pages/man5/core.5.html) man page.
278281

279-
##### Systemd
282+
#### Systemd Coredumpctl <a id="development-debug-core-dump-systemd"></a>
280283

284+
Most distributions offer systemd's coredumpctl either by default or as a package.
285+
Distributions that offer it by default include RHEL and SLES, on others like
286+
Debian or Ubuntu it can be installed via the `systemd-coredump` package.
287+
When set up correctly, `core_pattern` will look something like this:
288+
```
289+
# cat /proc/sys/kernel/core_pattern
290+
|/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h`
281291
```
282-
systemctl edit icinga2.service
283292

284-
[Service]
285-
...
286-
LimitCORE=infinity
293+
You can look at the generated core dumps with the `coredumpctl list` command.
294+
You can show information, including a stack trace using
295+
`coredumpctl show icinga2 -1` and retrieve the actual core dump file with
296+
`coredumpctl dump icinga2 -1 --output <file>`.
287297

288-
systemctl daemon-reload
298+
For further information on how to configure and use coredumpctl, read the man pages
299+
[coredumpctl(1)](https://man7.org/linux/man-pages/man1/coredumpctl.1.html) and
300+
[coredump.conf(5)](https://man7.org/linux/man-pages/man5/coredump.conf.5.html).
289301

290-
systemctl restart icinga2
302+
#### Ubuntu Apport <a id="development-debug-core-dump-apport"></a>
303+
304+
Ubuntu uses their own application `apport` to record core dumps. When it is
305+
enabled, your `core_pattern` will look like this:
306+
```
307+
# cat /proc/sys/kernel/core_pattern
308+
|/usr/share/apport/apport -p%p -s%s -c%c -d%d -P%P -u%u -g%g -- %E
291309
```
292310

293-
##### Init Script
311+
Apport is unsuitable for development work, because by default it only works
312+
with Ubuntu packages and it has a rather complicated interface for retrieving
313+
the core dump. So unless you rely on Apport for some other workflow, systemd's
314+
coredumpctl is a much better option and is available on Ubuntu in the
315+
`systemd-coredump` package that can replace Apport on your system with no
316+
further setup required.
294317

318+
If you still want to use Apport however, to set it up to work with unpackaged programs,
319+
add the following (create the file if it doesn't exist) to `/etc/apport/settings`:
295320
```
296-
vim /etc/init.d/icinga2
297-
...
298-
ulimit -c unlimited
299-
300-
service icinga2 restart
321+
[main]
322+
unpackaged=true
323+
```
324+
and restart Apport:
325+
```
326+
systemctl restart apport.service
301327
```
302328

303-
##### Verify
329+
When the program crashes you can then find an Apport crash report in `/var/crash/`
330+
that you can read with the interactive `apport-cli` command. To extract the core
331+
dump you run `apport-unpack /var/crash/<crash-file> <output-dir>` which then
332+
saves a `<outputdir>/CoreDump` file that contains the actual core dump.
304333

305-
Verify that the Icinga 2 process core file size limit is set to `unlimited`.
334+
#### Directly to a File <a id="development-debug-core-dump-direct"></a>
306335

307-
```
308-
for pid in $(pidof icinga2); do cat /proc/$pid/limits; done
336+
If coredumpctl is not available, simply writing the core dump directly to a file
337+
is also sufficient. You can set up your `core_pattern` to write a file to a
338+
suitable path:
309339

310-
...
311-
Max core file size unlimited unlimited bytes
340+
```bash
341+
sysctl -w kernel.core_pattern=/var/lib/cores/core.%e.%p.%h.%t
342+
install -m 1777 -d /var/lib/cores
312343
```
313344

345+
If you want to make this setting permanent you can also add a file to
346+
`/etc/sysctl.d`, named something like `80-coredumps.conf`:
347+
```
348+
kernel.core_pattern = /var/lib/cores/core.%e.%p.%h.%t
349+
```
314350

315-
#### Core Dump Kernel Format <a id="development-debug-core-dump-format"></a>
351+
This will create core dump files in `/var/lib/cores` where `%e` is the truncated
352+
name of the program, `%p` is the programs PID, `%h` is the hostname, and `%t` a
353+
timestamp.
316354

317-
The Icinga 2 daemon runs with the SUID bit set. Therefore you need
318-
to explicitly enable core dumps for SUID on Linux.
355+
Note that unlike the other methods this requires the core size limit to be set
356+
for the process. When starting Icinga 2 via systemd you can set it to unlimited
357+
by adding the following to `/etc/systemd/system/icinga2.service.d/limits.conf`:
358+
```
359+
[Service]
360+
LimitCORE=infinity
361+
```
319362

363+
Then reload and restart icinga:
320364
```bash
321-
sysctl -w fs.suid_dumpable=2
365+
systemctl daemon-reload
366+
systemctl restart icinga2.service
322367
```
323368

324-
Adjust the coredump kernel format and file location on Linux:
369+
Alternatively you edit and reload in one step:
370+
```bash
371+
systemctl edit --drop-in=limits icinga2.service`
372+
```
325373

374+
When using an init script or starting manually, you need to run `ulimit -c unlimited`
375+
before starting the program:
326376
```bash
327-
sysctl -w kernel.core_pattern=/var/lib/cores/core.%e.%p
377+
ulimit -c unlimited
378+
./icinga2 daemon
379+
```
328380

329-
install -m 1777 -d /var/lib/cores
381+
To verify that the limit has been set to `unlimited` run the following:
382+
```bash
383+
for pid in $(pidof icinga2); do cat /proc/$pid/limits; done
384+
```
385+
And look for the line:
386+
```
387+
Max core file size unlimited unlimited bytes
330388
```
331389
332-
MacOS:
390+
#### MacOS <a id="development-debug-core-dump-macos"></a>
333391
334392
```bash
335393
sysctl -w kern.corefile=/cores/core.%P
336-
337394
chmod 777 /cores
338395
```
339396

@@ -683,7 +740,7 @@ these tools:
683740
- vim
684741
- CLion (macOS, Linux)
685742
- MS Visual Studio (Windows)
686-
- Atom
743+
- Emacs
687744

688745
Editors differ on the functionality. The more helpers you get for C++ development,
689746
the faster your development workflow will be.
@@ -741,12 +798,12 @@ perfdata | Performance data related, including Graphite, Elastic, etc.
741798
db\_ido | IDO database abstraction layer.
742799
db\_ido\_mysql | IDO database driver for MySQL.
743800
db\_ido\_pgsql | IDO database driver for PgSQL.
744-
mysql\_shin | Library stub for linking against the MySQL client libraries.
801+
mysql\_shim | Library stub for linking against the MySQL client libraries.
745802
pgsql\_shim | Library stub for linking against the PgSQL client libraries.
746803

747804
#### Class Compiler <a id="development-develop-design-patterns-class-compiler"></a>
748805

749-
Another thing you will recognize are the `.ti` files which are compiled
806+
Something else you might notice are the `.ti` files which are compiled
750807
by our own class compiler into actual source code. The meta language allows
751808
developers to easily add object attributes and specify their behaviour.
752809

@@ -792,17 +849,18 @@ The most common benefits:
792849

793850
#### Unity Builds <a id="development-develop-builds-unity-builds"></a>
794851

795-
Another thing you should be aware of: Unity builds on and off.
852+
You should be aware that by default unity builds are enabled. You can turn them
853+
off by setting the `ICINGA2_UNITY_BUILD` CMake option to `OFF`.
796854

797855
Typically, we already use caching mechanisms to reduce recompile time with ccache.
798856
For release builds, there's always a new build needed as the difference is huge compared
799857
to a previous (major) release.
800858

801-
Therefore we've invented the Unity builds, which basically concatenates all source files
802-
into one big library source code file. The compiler then doesn't need to load the many small
803-
files but compiles and links this huge one.
859+
Unity builds basically concatenate all source files into one big library source code file.
860+
The compiler then doesn't need to load many small files, each with all of their includes,
861+
but compiles and links only a few huge ones.
804862

805-
Unity builds require more memory which is why you should disable them for development
863+
However, unity builds require more memory which is why you should disable them for development
806864
builds in small sized VMs (Linux, Windows) and also Docker containers.
807865

808866
There's a couple of header files which are included everywhere. If you touch/edit them,
@@ -1228,7 +1286,7 @@ every second.
12281286
12291287
Avoid log messages which could irritate the user. During
12301288
implementation, developers can change log levels to better
1231-
see what's going one, but remember to change this back to `debug`
1289+
see what's going on, but remember to change this back to `debug`
12321290
or remove it entirely.
12331291

12341292

@@ -2262,7 +2320,7 @@ cmake .. -DCMAKE_INSTALL_PREFIX=/tmp/icinga2
22622320

22632321
### CMake Variables <a id="development-package-builds-cmake-variables"></a>
22642322

2265-
In addition to `CMAKE_INSTALL_PREFIX` here are most of the supported Icinga-specific cmake variables.
2323+
In addition to `CMAKE_INSTALL_PREFIX` here are most of the supported Icinga-specific CMake variables.
22662324

22672325
For all variables regarding defaults paths on in CMake, see
22682326
[GNUInstallDirs](https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html).

0 commit comments

Comments
 (0)