Last active
December 11, 2015 16:48
-
-
Save justinstoller/4630022 to your computer and use it in GitHub Desktop.
An example smf property defined type (I don't remember if it works...)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# This provides simple setting of smf service properties idempotently | |
# Usage: | |
# smf_prop { 'application/pkg/server pkg/port=blah': } | |
# | |
# Example (from my defunct ips repo manifest | |
# Smf_prop { | |
# notify => Service[ $service ], | |
# require => Exec[ "create-pkgrepo-${path}" ], | |
# } | |
# | |
# smf_prop { "${service} pkg/inst_root=${path}": } | |
# smf_prop { "${service} pkg/port=${port}": } | |
# smf_prop { "${service} pkg/readonly=${readonly}": } | |
# smf_prop { "${service} pkg/threads=${threads}": } | |
# smf_prop { "${service} pkg/proxy_base=${proxy}": } | |
# | |
# service { $service: enable => true, ensure => running, } | |
# | |
define smf_prop ( | |
$title = $name, | |
$ensure = 'present' | |
) { | |
$service_holder = split $title, ' ' | |
$key_value = split $service_holder[1], '=' | |
$service = $service_holder[0] | |
$prop = $key_value[0] | |
$value = $key_value[1] | |
# shorter commands please | |
$listval = 'listprop -o value' | |
Exec { path => [ '/bin', '/usr/bin', '/sbin', '/usr/sbin' ], logoutput => on_failure } | |
if $ensure == 'present' { | |
# if the value is blank then we can ensure the property is present | |
# but that it's value is unset | |
if $value == '' { | |
exec { "unset-${service}-${prop}": | |
command => "svccfg -s ${service} delpropvalue ${prop}", | |
unless => "svccfg -s ${service} ${listval} ${prop} | grep ' '", | |
} | |
} else { | |
# otherwise set the value hard! | |
exec { "set-${service}-${prop}-to-${value}": | |
command => "svccfg -s ${service} setprop ${prop} = ${value}", | |
unless => "svccfg -s ${service} ${listval} ${prop} | grep ${value}", | |
} | |
} elsif $ensure == 'absent' { | |
# if the value wasn't set then we will remove the property altogether | |
if $value == '' { | |
exec { "remove-${prop}-from-${service}": | |
command => "svccfg -s ${service} delprop ${prop}", | |
unless => "svccfg -s ${service} listprop ${prop} | grep ${prop}", | |
} | |
} else { | |
# otherwise we'll remove the property from a set of them | |
exec { "remove-${value}-from-${service}-${prop}": | |
command => "svccfg -s ${service} delpropvalue ${prop} ${value}", | |
unless => "svccfg -s ${service} ${listval} ${prop} | grep ${value}", | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment