Commit 68c6c6f5 authored by Christopher Huhn's avatar Christopher Huhn
Browse files

Increase robustness of sys_systemd_unit

parent 6f160f1b
......@@ -265,6 +265,15 @@ suites:
- root
rules:
- "SMUTJE ALL=(ALL) NOPASSWD: ALL"
- name: sys_systemd
run_list:
- recipe[sys::systemd]
attributes:
sys:
systemd:
unit:
unknown_method:
whatever: "Should throw an error but converge"
- name: sys_time
run_list:
- recipe[sys::time]
......
......@@ -16,4 +16,4 @@ supports 'debian'
depends 'line', '< 1.0'
depends 'chef-vault'
version '1.60.5'
version '1.60.6'
#
# Cookbook Name:: sys
# Provider for custom resource sys_systemd_unit
#
# Copyright 2015-2016 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
#
# Authors:
# Dennis Klein <d.klein@gsi.de>
# Victor Penso <v.penso@gsi.de>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
use_inline_resources
action :create do
......@@ -81,7 +104,14 @@ end
def unit
if new_resource.type.nil?
name, type = new_resource.name.match(/^(.*)\.([^\.]*)$/).values_at(1,2)
if new_resource.name.match(/^(.*)\.(.*?)$/)
name = Regexp.last_match(1)
type = Regexp.last_match(2)
else
# assume type service if not explicitly given:
name = new_resource.name
type = 'service'
end
else
name = new_resource.name
type = new_resource.type
......
......@@ -2,7 +2,12 @@
# Cookbook Name:: sys
# Recipe:: systemd
#
# Copyright 2015, Dennis Klein
# Copyright 2015-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
#
# Authors:
# Christopher Huhn <c.huhn@gsi.de>
# Dennis Klein <d.klein@gsi.de>
# Thomas Roth <t.roth@gsi.de>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -42,7 +47,12 @@ if systemd_installed? # We do not install systemd for now, just detect if it is
node['sys']['systemd']['unit'].each do |name, config|
sys_systemd_unit name do
config.each do |key, value|
send(key, value)
begin
send(key, value)
rescue NoMethodError => e
Chef::Log.error("sys_systemd_unit[#{name}]: "\
"No property '#{key}' (#{e})")
end
end
end
end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment