Skip to content
This repository has been archived by the owner on Mar 6, 2020. It is now read-only.

permit symlinks in config directory #18

Merged
merged 3 commits into from
Aug 6, 2015
Merged

permit symlinks in config directory #18

merged 3 commits into from
Aug 6, 2015

Conversation

roobert
Copy link
Contributor

@roobert roobert commented Jul 13, 2015

We have a situation where our conf.d directory is maintained by Puppet, but our application layer is deployed by Ansible. We deploy apps into opt/<app>-<instance> and the sensu check configs into a subdir called checks. We then create a symlink /etc/sensu/conf.d/app/<app>-<id> to the checks dir so that if an app gets removed we're just left with a dead symlink, rather than Sensu loading checks for apps that have been removed. Later, a puppet job comes along and removes dead symlinks.

Convoluted, I know. Regardless, I think permitting symlinks in conf.d should be acceptable :)

@portertech
Copy link
Contributor

You can specify multi configuration directories in /etc/default/sensu with CONFIG_DIR=/some/dir,/another/dir.

@roobert
Copy link
Contributor Author

roobert commented Jul 16, 2015

@portertech: this ok?

@@ -139,7 +139,7 @@
it "can load settings from files in a directory" do
@loader.load_directory(@config_dir)
warnings = @loader.warnings
expect(warnings.size).to eq(4)
expect(warnings.size).to eq(6)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did this increase by 2?

Copy link
Contributor

Choose a reason for hiding this comment

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

"loading config file" & "config file applied changes"

…support doesn't add possibility of causing an infinite loop
@@ -124,7 +124,7 @@ def load_file(file)
def load_directory(directory)
warning("loading config files from directory", :directory => directory)
path = directory.gsub(/\\(?=\S)/, "/")
Dir.glob(File.join(path, "**/*.json")).each do |file|
Dir.glob(File.join(path, "**{,/*/**}/*.json")).uniq.each do |file|
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the uniq() for? Shouldn't have duplicate file paths, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The glob seems to match files multiple times:

[7] pry(main)> Dir.glob(File.join("**/*.json")) { |i| puts i }
nested/file.json
merger.json
=> nil
[8] pry(main)> Dir.glob(File.join("**{,/*/**}/*.json")) { |i| puts i }
nested/file.json
merger.json
nested/file.json
alternative/symlinked.json
=> nil

Took the glob from here: http://stackoverflow.com/questions/357754/can-i-traverse-symlinked-directories-in-ruby-with-a-glob

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems we need a uniq() anyways, as this pattern along w/ alternatives, will pick up a symlink to a dir that it has already listed 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Although, it is still a uniq file path :P

@roobert
Copy link
Contributor Author

roobert commented Jul 26, 2015

gif

portertech added a commit that referenced this pull request Aug 6, 2015
@portertech portertech merged commit 4162098 into sensu:master Aug 6, 2015
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