File: init.rb

package info (click to toggle)
puppet-module-puppetlabs-apache 5.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 2,252 kB
  • sloc: ruby: 422; sh: 44; makefile: 6
file content (34 lines) | stat: -rwxr-xr-x 892 bytes parent folder | download
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
32
33
34
#!/usr/bin/ruby
require 'json'
require 'open3'
require 'puppet'

def service(action, service_name)
  if service_name.nil?
    stdout, _stderr, _status = Open3.capture3('facter', '-p', 'osfamily')
    osfamily = stdout.strip
    service_name = if osfamily == 'RedHat'
                     'httpd'
                   elsif osfamily == 'FreeBSD'
                     'apache24'
                   else
                     'apache2'
                   end
  end
  _stdout, stderr, status = Open3.capture3('service', service_name, action)
  raise Puppet::Error, stderr if status != 0
  { status: "#{action} successful" }
end

params = JSON.parse(STDIN.read)
action = params['action']
service_name = params['service_name']

begin
  result = service(action, service_name)
  puts result.to_json
  exit 0
rescue Puppet::Error => e
  puts({ status: 'failure', error: e.message }.to_json)
  exit 1
end