Skip to content
This repository has been archived by the owner on May 3, 2023. It is now read-only.

contrib: integrate with systemd units #61

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pothos
Copy link
Member

@pothos pothos commented May 31, 2021

The benchmark script in contrib/ already used ExecStartPre to
automatically set up systemd unit tracing. This was quite verbose and
and also lacked the "+" prefix to refer to the host filesystem and run
as root even if the unit processes are sandboxed.
Document how to modify systemd units so that they register with
traceloop. For convenience this is based on a traceloop service file
and new helper tool traceloopctl in the contrib folder. The
traceloopctl tool has a special systemd mode which follows a naming
scheme for a better integration but the traceloopctl can also be used
in the generic mode to interact with any trace.

Type=notify
NotifyAccess=all
ExecStartPre=/bin/rm -f /run/traceloop.socket
ExecStart=/bin/sh -c "/home/kai/kinvolk/traceloop/traceloop serve & while ! curl -fsS --unix-socket /run/traceloop.socket 'http://localhost/list' > /dev/null; do sleep 1; echo Waiting for traceloop to start up; done ; systemd-notify --ready; wait"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of calling systemd-notify, you could do it in Golang:
https://vincent.bernat.ch/en/blog/2017-systemd-golang
https://github.com/coreos/go-systemd/blob/v22.3.2/daemon/sdnotify.go#L56

daemon.SdNotify(false, daemon.SdNotifyReady)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, with ignoring the return code (false, nil) it should be fine when used outside of a systemd unit.

elif [ "$CMD" = list-sd-units ]; then
echo " Traces Units"
echo "------- -----"
$CURL "http://localhost/list" | grep -o '\[systemd_.*\]' | cut -d _ -f 2 | sort | uniq -c
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The systemd-specific commands *-sd could be added in the Go program, so that the shell script could be simplified. (could be in a follow-up PR)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And internally traceloop with still concatenate a special name or would you introduce a new attributes for Tracelet?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess introducing new attributes but I have not given it much thought. Do you have a preference?

@pothos pothos force-pushed the kai/trace-systemd-services branch from 1b63177 to 4a2e4df Compare May 31, 2021 16:26
The benchmark script in contrib/ already used ExecStartPre to
automatically set up systemd unit tracing. This was quite verbose and
and also lacked the "+" prefix to refer to the host filesystem and run
as root even if the unit processes are sandboxed.
Document how to modify systemd units so that they register with
traceloop. For convenience this is based on a traceloop service file
and new helper tool traceloopctl in the contrib folder. The
traceloopctl tool has a special systemd mode which follows a naming
scheme for a better integration but the traceloopctl can also be used
in the generic mode to interact with any trace.
@pothos pothos force-pushed the kai/trace-systemd-services branch from 4a2e4df to 51b2479 Compare May 31, 2021 16:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants