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
stracewith the service binary inExecStart. For that, find out the existingExecStartof the service by using the command:Terminal window systemctl cat <service-name>.service | grep ExecStartIt will give command line options used with service binary.
-
Override
ExecStartof the service to attachstrace. We will use the same options withstraceto replicate the same scenario. For example, to attachstracewithauditdservice 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 nochangecommand is used in the regularExecStartofauditdservice. In the above command, we attachedstracewith the command, which will generate system call traces in/etc/auditd_trace.logfile. -
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.