Mercurial > repos > other > Puppet
diff modules/apache/tasks/init.rb @ 275:d9352a684e62
Mass update of modules to remove deprecation warnings
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 26 Jan 2020 11:36:07 +0000 |
parents | |
children | b8d6ada284dd |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/apache/tasks/init.rb Sun Jan 26 11:36:07 2020 +0000 @@ -0,0 +1,34 @@ +#!/opt/puppetlabs/puppet/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