Skip to content

Commit

Permalink
Merge pull request #6 from kenhys/add-more-message
Browse files Browse the repository at this point in the history
Logging actual config path when error has been occurred
  • Loading branch information
ashie committed Apr 3, 2021
2 parents e0d9a5b + 359d797 commit f0f0ff7
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions collectd/monitor/config-replacer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,29 @@ function run(self)
return false, self.result.message
end

local config_path = self:config_path()
local old_config_path = self:old_config_path()
local new_config_path = self:new_config_path()

-- save old config
succeeded, err = os.rename(self:config_path(), self:old_config_path())
succeeded, err = os.rename(config_path, old_config_path)
if not succeeded then
message = string.format("Failed to back up old config file! (<%s> => <%s>): %s",
config_path, old_config_path, err)
self:error(message)
self.result.code = ConfigReplacer.ERROR_CANNOT_BACKUP_CONFIG
self.result.message = "Failed to back up old config file!: " .. err
self.result.message = message
return false, self.result.message
end

-- replace the config with new one
succeeded, err = os.rename(self:new_config_path(), self:config_path())
succeeded, err = os.rename(new_config_path, config_path)
if not succeeded then
message = string.format("Failed to replace config file! (%s => %s): %s",
new_config_path, config_path, err)
self:error(message)
self.result.code = ConfigReplacer.ERROR_CANNOT_REPLACE_CONFIG
self.result.message = "Failed to replace config file!: " .. err
self.result.message = message
return false, self.result.message
end

Expand Down

0 comments on commit f0f0ff7

Please sign in to comment.