Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to define multiple checks/services #212

Merged
merged 1 commit into from
Aug 28, 2015

Conversation

scalp42
Copy link
Contributor

@scalp42 scalp42 commented Aug 27, 2015

Hi @johnbellone

You can define multiple checks/services at once, this should fix it to get around this issue: #201 (comment)

johnbellone added a commit that referenced this pull request Aug 28, 2015
allow to define multiple checks/services
@johnbellone johnbellone merged commit 4bb8bc1 into sous-chefs:master Aug 28, 2015
@csghuser
Copy link

csghuser commented Sep 7, 2015

Hi @scalp42, many thanks for this, can you give an example so I can give it a try? Not sure on the syntax. I tried something similar to the following but it failed to compile:

consul_definition node['consul_agent']['service_name'] do
  type 'checks'
  parameters(
    {
            id: 'disk-util',
            name: 'Disk Util',
            notes: 'Critical 95%, warning 90% used',
            script: '/usr/local/bin/check_disks.sh -v / -c 95 -w 90',
            interval: '1m'
    },
    {
            id: 'cpu-load',
            name: 'CPU Load',
            notes: 'Auto detects load/cpus',
            script: '/usr/local/bin/check_load.sh -a',
            interval: '1m'
    }
  )
    notifies :reload, 'consul_service[consul]',:delayed
end

Error was:

ArgumentError
       -------------
       wrong number of arguments (2 for 0..1)

@Bhuwan
Copy link

Bhuwan commented Apr 3, 2017

I know this is really old but I spent a few minutes trying to figure this out myself. Something similar to this worked:

consul_definition node['consul_agent']['service_name'] do
  type 'checks'
  parameters({
    disk-util:
    {
            id: 'disk-util',
            name: 'Disk Util',
            notes: 'Critical 95%, warning 90% used',
            script: '/usr/local/bin/check_disks.sh -v / -c 95 -w 90',
            interval: '1m'
    },
    cpu-load: 
    {
            id: 'cpu-load',
            name: 'CPU Load',
            notes: 'Auto detects load/cpus',
            script: '/usr/local/bin/check_load.sh -a',
            interval: '1m'
    }
  })
    notifies :reload, 'consul_service[consul]',:delayed
end

Thanks, hope this helps future posters :)

@scalp42
Copy link
Contributor Author

scalp42 commented Apr 6, 2017

Really sorry about that @csghuser and @Bhuwan, totally missed the notification.

I ended up going the service route instead as it made more sense for us:

service_status = node['my-consul']['service'].map do |a, s|
  case a.to_s
  when 'enable'
    s == false ? :disable : :enable
  end
end

consul_definition 'mesos-master' do
  type 'service'
  parameters(
    port: port,
    tags: %W|#{node.chef_environment}|,
    checks: [
      {
        script: %|nc -z -v -w1 #{node['ipaddress']} 5050|,
        interval: '5s',
        timeout: '3s',
        notes: %|nc -z -v -w2 #{node['ipaddress']} 5050|
      }
    ]
  )
  action :create # :delete
  unless node['is_packer']
    notifies :reload, 'consul_service[consul]', :delayed unless service_status.any? { |x| [:disable].include?(x) }
  end
end

Hopefully it helps!

@lock
Copy link

lock bot commented Apr 25, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 25, 2020
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.

None yet

4 participants