File: init.rb

package info (click to toggle)
puppet-module-puppetlabs-apache 12.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,664 kB
  • sloc: ruby: 275; sh: 32; makefile: 2
file content (37 lines) | stat: -rwxr-xr-x 925 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
35
36
37
#!/usr/bin/ruby
# frozen_string_literal: true

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