### ### Copyright 2000-2007 University of Illinois Board of Trustees ### All rights reserved. ### ### PSGConf::Action::svcs::setprop - setting svcs property action type for psgconf ### ### Campus Information Technologies and Educational Services ### University of Illinois at Urbana-Champaign ### package PSGConf::Action::svcs::setprop; use strict; use PSGConf::Action; use PSGConf::Util; our @ISA = qw(PSGConf::Action); ############################################################################### ### check method ############################################################################### sub check { my ($self, $psgconf) = @_; my ($cmd, $value, $output); $value = $self->{value}; $cmd = '/usr/sbin/svccfg'; $cmd .= ' -s ' . $self->{FMRI} if ( $self->{FMRI} ); $cmd .= ' listprop ' . $self->{property}; if ( ! open (SVCCFG, "$cmd 2>&1|" )) { warn "\n\t!!! cannot run ($cmd): $!\n"; return -1 } $output = ; close SVCCFG; ### Massage ${value} to remove the TYPE: from the ### 'TYPE: value' format so our test works better. ${value} =~ s/[^ ]*: //; if ( $output =~ /${value}$/ ) { return 0; } else { $self->{changed} = 1; return 1; } } ############################################################################### ### diff method ############################################################################### sub diff { my ($self) = @_; my ($cmd); $cmd = '/usr/sbin/svccfg'; $cmd .= ' -s ' . $self->{FMRI} if ( $self->{FMRI} ); $cmd .= ' setprop ' . $self->{property}; $cmd .= ' = ' . $self->{value}; print "###############################################################################\n"; print "### DIFF FOR $self->{name}\n"; print "###############################################################################\n"; print "+ setprop: ${cmd}\n"; print "\n"; } ############################################################################### ### do() method ############################################################################### sub do { my ($self) = @_; my ($cmd, $val, $res); $cmd = '/usr/sbin/svccfg'; $cmd .= ' -s ' . $self->{FMRI} if ( $self->{FMRI} ); $cmd .= ' setprop ' . $self->{property}; ### Escape any " or ' in value $val = $self->{value}; $val =~ s/(['"])/\\$1/g; $cmd .= ' = ' . $val; $res=!(&PSGConf::Util::RunCommand(${cmd})); ### If we failed, then return right away return $res if ( ! $res); if ($self->{refresh}) { ### Otherwise we need to refresh the service $cmd = '/usr/sbin/svcadm refresh ' . $self->{FMRI}; return (!&PSGConf::Util::RunCommand(${cmd})); } return 1; } ############################################################################### ### documentation ############################################################################### 1; __END__ =head1 NAME PSGConf::Action::svcs::setprop - setting svcs property action type for psgconf =head1 SYNOPSIS use PSGConf::Action::svcs::setprop; $psgconf->register_actions( PSGConf::Action::svcs::setprop->new( 'name' => 'message about property being set', 'FMRI' => 'The FMRI to work on ...', 'property' => 'property to set ...', 'value' => 'value to set the property to ...', ), ... ); =head1 DESCRIPTION The B module provides a B action class for configuring the System Management Facility . The B class is derived from the B class, but it defines/overrides the following methods: =over 4 =item check() Checks to see what value the I is set to, and compares it to I. If they are different, it sets the changed flag so that later on, the C and C will get run. =item diff() Prints a message indicating that C will be executed. =item do() Actually executes the C and C commands. =back In addition to the attributes supported by the B class, the B class supports the following attributes: =over 4 =item I The Fault Management Resource Identifier where the property resides. =item I The property to be changed =item I The value to change the property to. =item I true if the service should be refreshed via svcadm =back Note that the I attribute will only be used to print the "checking" message when the check() method is called. =head1 SEE ALSO Csmf(5)E> Csvccfg(1m)E> L L L =cut