File: ruby.rb

package info (click to toggle)
puppet-module-puppetlabs-rabbitmq 8.5.0-10
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,192 kB
  • sloc: ruby: 5,227; sh: 10; makefile: 4
file content (31 lines) | stat: -rw-r--r-- 1,014 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require 'puppet'
require 'set'
Puppet::Type.type(:rabbitmq_erlang_cookie).provide(:ruby) do
  confine feature: :posix

  def exists?
    # Hack to prevent the create method from being called.
    # We never need to create or destroy this resource, only change its value
    true
  end

  def content=(value)
    raise('The current erlang cookie needs to change. In order to do this the RabbitMQ database needs to be wiped.  Please set force => true to allow this to happen automatically.') unless resource[:force] == :true # Danger!

    Puppet::Type.type(:service).new(name: resource[:service_name]).provider.stop
    FileUtils.rm_rf(resource[:rabbitmq_home] + File::SEPARATOR + 'mnesia')
    File.open(resource[:path], 'w') do |cookie|
      cookie.chmod(0o400)
      cookie.write(value)
    end
    FileUtils.chown(resource[:rabbitmq_user], resource[:rabbitmq_group], resource[:path])
  end

  def content
    if File.exist?(resource[:path])
      File.read(resource[:path])
    else
      ''
    end
  end
end