nathwill / chef-systemd

resource-driven chef cookbook for managing linux systems via systemd
Apache License 2.0
44 stars 33 forks source link

new systemd_service syntax conflicts with chef-sugar cookbook #103

Closed dragonsmith closed 7 years ago

dragonsmith commented 7 years ago

Hello, We found out that your new refactored syntax is being broken by chef-sugar cookbook. More precisely by this method: https://github.com/sethvargo/chef-sugar/blob/master/lib/chef/sugar/filters.rb#L148

if we add chef-sugar to our run_list or as a dependency than the following example code will fail:

  systemd_service 'node_exporter' do
    unit do
      description 'Systemd unit for Prometheus Node Exporter'
      after %w(network.target remote-fs.target)
      action :create
    end
    action [:create]
    install do
      wanted_by 'multi-user.target'
    end
    service do
      type 'simple'
      exec_start "/usr/local/sbin/node_exporter #{options}"
      working_directory '/'
      restart 'on-failure'
      restart_sec '30s'
    end
  end

with the following error:

    ArgumentError
    -------------
    Must pass a Chef::Resource or String to lookup

which is raised by the 4th line from the example.

I understand it is the tricky situation where chef-sugar cookbook cuts some corners, but it is already integrated into other third-party cookbooks e.g. consul (like in our case).

I'm kinda unsure even what to purpose because the after method from chef-sugar becomes available after the compilation stage (if I understand it right).

What do you think?

Thank you very much!

nathwill commented 7 years ago

thanks for the heads up @dragonsmith (and for doing early testing!) i'll play around with this a bit and see if i can find a solution.

nathwill commented 7 years ago

wild... so for now, you can work around this by using the long-form (i.e. unit_after/unit_before):

  systemd_service 'node_exporter' do
    unit_after %w(network.target remote-fs.target)
    unit do
      description 'Systemd unit for Prometheus Node Exporter'
    end
    install do
      wanted_by 'multi-user.target'
    end
    service do
      type 'simple'
      exec_start "/usr/local/sbin/node_exporter #{options}"
      working_directory '/'
      restart 'on-failure'
      restart_sec '30s'
    end
    action :create
  end

and i'm kind of inclined to leave this there and send this to chef-sugar as a bug at this point...

nathwill commented 7 years ago

well, after a little bit of futzing around, i think i found a way to prevent the method_missing hijinks from letting the resource find chef-sugar's before/after methods before trying unit_before, unit_after... https://github.com/nathwill/chef-systemd/pull/94/commits/4d2ede2cb282ca674b6218905acc16687d7ac3f9