Using strace for Debugging Initialization Sequence
strace
can give detailed information about system calls made by a service. This is helpful in debugging restrictions applied to system calls and the capability of any service. Though we can attach strace
with the PID of a running process, sometimes we may need to debug the service initialization sequence.
To debug the initialization sequence:
-
Attach
strace
with the service binary inExecStart
. For that, find out the existingExecStart
of the service by using the command:$> systemctl cat <service-name>.service | grep ExecStart
It will give command line options used with service binary.
-
Override
ExecStart
of the service to attachstrace
. We will use the same options withstrace
to replicate the same scenario. For example, to attachstrace
withauditd
service we will use the following configuration at a suitable location:systemd.services."auditd".serviceConfig.ExecStart = lib.mkForce "${pkgs.strace}/bin/strace -o /etc/auditd_trace.log ${pkgs.audit}/bin/auditd -l -n -s nochange";
The
${pkgs.audit}/bin/auditd -l -n -s nochange
command is used in the regularExecStart
ofauditd
service. In the above command, we attachedstrace
with the command, which will generate system call traces in/etc/auditd_trace.log
file. -
After modifying above configuration, rebuild and load a Ghaf image.
The log may give you information about the system call restriction that caused the service failure. You can tune your service config accordingly.