Sensu agent uses a reasonable default cache directory for each platform
Sensu agent uses /var/cache/sensu, but fails to create the directory on macOS because /var/cache doesn't exist.
Create a macOS specific default path in path.go e.g. /Library/Caches/sensu.
--cache-dir from CLI and cache-dir from agent config.Brought up by a user in #sensu2 community slack.
This will happen on all platforms when trying to run the binary as a non-root user without installing sensu-agent via packages.
@grepory has previously suggested making path defaults relative to the directory in which sensu-agent is run from. For example:
Running sensu-agent from ~/test/ would create ~/test/cache/sensu.
System-level path defaults can instead be specified in config files and loaded with the -c flag.
That please.
Is there an issue already created for switching to relative paths? If not, I can create one.
I've added the macOS specific cache directory (/Library/Caches) as part of #2132. It may not be the full solution we want, but it does make sensu-agent on macOS less broken. Would you be willing to accept this PR as a step in the right direction?
I don't believe that an issue has been created yet.
I'd like to hold off on changing the defaults until we have a finalized solution. The reason being that it's an additional location to worry about manually cleaning up when we implement relative paths.
You should be able to specify the cache dir when you start sensu-agent (e.g. sensu-agent start --cache-dir /tmp). Will this work for you for the interim?
That's a fair point from the cleanup perspective. Manually specifying a --cache-dir is what I suggested to our user in #sensu2. I'll remove the path change from the PR.
Most helpful comment
This will happen on all platforms when trying to run the binary as a non-root user without installing sensu-agent via packages.
@grepory has previously suggested making path defaults relative to the directory in which sensu-agent is run from. For example:
Running sensu-agent from
~/test/would create~/test/cache/sensu.System-level path defaults can instead be specified in config files and loaded with the
-cflag.