Lars Tobias Skjong-Børsting
2010-Sep-15 06:35 UTC
[Puppet Users] Glassfish asadmin provider
Hi, I am making a resource type to manage Glassfish domains. I''m not quite sure how to specify provider commands with a sane default and in configurable way. The location of the binary may be in other locations depending on where Glassfish was installed. http://github.com/larstobi/puppet-glassfish/blob/master/lib/puppet/provider/glassfish/asadmin.rb Does anyone have any advice on this? -- Regards, Lars Tobias -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
2010/9/14 Lars Tobias Skjong-Børsting <lists@snota.no>> I am making a resource type to manage Glassfish domains. I''m not quite sure > how to specify provider commands with a sane default and in configurable > way. The location of the binary may be in other locations depending on where > Glassfish was installed. > > > http://github.com/larstobi/puppet-glassfish/blob/master/lib/puppet/provider/glassfish/asadmin.rb > > Does anyone have any advice on this? >Check some hard coded path, and tries to detect if it''s available in $PATH using which: case when File.executable?("/opt/NSBglassfish/bin/asadmin") commands :asadmin => "/opt/NSBglassfish/bin/asadmin" when File.executable?("/usr/local/NSBglassfish/bin/asadmin") commands :asadmin => "/usr/local/NSBglassfish/bin/asadmin" else asadmin_path = `which asadmin` if $?.exitstatus ==0 commands :asadmin => asadmin_path else raise Puppet::Error, "Unable to locate asadmin in $PATH" end end Disclaimer, I''m just looking into writing providers as well, so not sure if this is the best way. Anyone with more ruby experience feel free to chime in. Also if you run into other roadblocks, please try the puppet-dev mailing list as well. Thanks, Nan -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
* Nan Liu <nan at puppetlabs.com> [2010/09/15 12:08]:> Check some hard coded path, and tries to detect if it''s available in $PATH > using which: > > case > when File.executable?("/opt/NSBglassfish/bin/asadmin") > commands :asadmin => "/opt/NSBglassfish/bin/asadmin" > when File.executable?("/usr/local/NSBglassfish/bin/asadmin") > commands :asadmin => "/usr/local/NSBglassfish/bin/asadmin" > else > asadmin_path = `which asadmin` > if $?.exitstatus ==0 > commands :asadmin => asadmin_pathI have no comment on the general approach, but just wanted to point out that checking $? doesn''t necessarily work everywhere: $ uname -a ; which asdf ; echo $? SunOS smacky 5.10 Generic_142900-03 sun4v sparc SUNW,Sun-Fire-T200 Solaris no asdf in /usr/local/bin /usr/ccs/bin /usr/bin /bin 0 I''ve been bitten by this several times (though never in puppet). -- The Net views censorship as a network failure, and routes around it. -- John Gilmore -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Wed, Sep 15, 2010 at 12:25 PM, Darren Chamberlain <darren@boston.com> wrote:> * Nan Liu <nan at puppetlabs.com> [2010/09/15 12:08]: >> Check some hard coded path, and tries to detect if it''s available in $PATH >> using which: >> >> case >> when File.executable?("/opt/NSBglassfish/bin/asadmin") >> commands :asadmin => "/opt/NSBglassfish/bin/asadmin" >> when File.executable?("/usr/local/NSBglassfish/bin/asadmin") >> commands :asadmin => "/usr/local/NSBglassfish/bin/asadmin" >> else >> asadmin_path = `which asadmin` >> if $?.exitstatus ==0 >> commands :asadmin => asadmin_path > > I have no comment on the general approach, but just wanted to point > out that checking $? doesn''t necessarily work everywhere: > > $ uname -a ; which asdf ; echo $? > SunOS smacky 5.10 Generic_142900-03 sun4v sparc SUNW,Sun-Fire-T200 Solaris > no asdf in /usr/local/bin /usr/ccs/bin /usr/bin /bin > 0 > > I''ve been bitten by this several times (though never in puppet).Does ''type --all asdf'' do the right thing on SunOS ?> > -- > The Net views censorship as a network failure, and routes around it. > -- John Gilmore > > -- > You received this message because you are subscribed to the Google Groups "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en. > >-- nigel -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
* Nigel Kersten <nigelk at google.com> [2010/09/15 12:30]:> On Wed, Sep 15, 2010 at 12:25 PM, Darren Chamberlain <darren@boston.com> wrote: > > I have no comment on the general approach, but just wanted to point > > out that checking $? doesn''t necessarily work everywhere: > > > > $ uname -a ; which asdf ; echo $? > > SunOS smacky 5.10 Generic_142900-03 sun4v sparc SUNW,Sun-Fire-T200 Solaris > > no asdf in /usr/local/bin /usr/ccs/bin /usr/bin /bin > > 0 > > > > I''ve been bitten by this several times (though never in puppet). > > Does ''type --all asdf'' do the right thing on SunOS ?$ uname -a ; /bin/type --all asdf ; echo $? SunOS smacky 5.10 Generic_142900-03 sun4v sparc SUNW,Sun-Fire-T200 Solaris asdf not found 127 Nope. Note that this is solaris type, not GNU type. Of the machines I have access to (linux, freebsd, osx, opensolaris), (pre-11) solaris which seems to be the only one that (mis)behaves this way. -- Things exist, they''re just not there. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
* Darren Chamberlain <darren at boston.com> [2010/09/15 15:41]:> * Nigel Kersten <nigelk at google.com> [2010/09/15 12:30]: > > Does ''type --all asdf'' do the right thing on SunOS ? > > $ uname -a ; /bin/type --all asdf ; echo $? > SunOS smacky 5.10 Generic_142900-03 sun4v sparc SUNW,Sun-Fire-T200 Solaris > asdf not found > 127 > > Nope.Er, I mean, yes, type returns non-0. -- One of the symptoms of an approaching nervous breakdown is the belief that one''s work is terribly important. -- Bertrand Russell -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Wed, 15 Sep 2010, Nigel Kersten wrote:> Does ''type --all asdf'' do the right thing on SunOS ?According to IEEE Std 1003.1, 2004 Edition, "type" does not take any options. Anyway, on Solaris-5.8: for shell in /bin/sh /usr/xpg4/bin/sh /bin/ksh /usr/local/bin/bash ; do echo "[$shell]"; ${shell} -c ''type --all asdf; echo status=$?'' ; done [/bin/sh] --all not found asdf not found status=1 [/usr/xpg4/bin/sh] asdf not found status=127 [/bin/ksh] asdf not found status=127 [/usr/local/bin/bash] /usr/local/bin/bash: line 0: type: asdf: not found status=1 On NetBSD-5.99.27: for shell in /bin/sh /bin/ksh /usr/pkg/bin/bash ; do echo "[$shell]"; ${shell} -c ''type --all asdf; echo status=$?'' ; done [/bin/sh] type: Illegal option -- status=2 [/bin/ksh] /bin/ksh: whence: --: unknown option status=1 [/usr/pkg/bin/bash] /usr/pkg/bin/bash: line 0: type: asdf: not found status=1 I have seen systems where "type" prints a message about "command not found" (or words to that effect) but sets exit status 0 as if it had been successful. I have found that "command -v" does the right thing on the same system. Unfortunately, my notes from the time I noticed this don''t say which system had the problem, but I think it was AIX or Cygwin. Compare the POSIX description of the exit status for "type" and "command" at <http://www.opengroup.org/onlinepubs/009695399/utilities/type.html> and <http://www.opengroup.org/onlinepubs/009695399/utilities/command.html>: For "type" exit status >0 means "an error occurred", while for "command" exit status >0 means "the command_name could not be found or an error occurred". What I take from the POSIX spec is that one could argue either way about whether or not it''s an error for the "type" command to report that a target command does not exist; but for the "command -v" command it''s clear that nonexistence of the target command should result in non-zero exit status. --apb (Alan Barrett) -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Hi, Thanks for all suggestions! I finally went for Nan Liu''s solution by checking the $PATH environment variable for an executable. The resulting commit is here: http://github.com/larstobi/puppet-glassfish/commit/047f82 diff --git a/lib/puppet/provider/glassfish/asadmin.rb b/lib/puppet/provider/glassfish/asadmin.rb index d2009a7..56abe71 100644 --- a/lib/puppet/provider/glassfish/asadmin.rb +++ b/lib/puppet/provider/glassfish/asadmin.rb @@ -1,7 +1,17 @@ Puppet::Type.type(:glassfish).provide(:asadmin) do desc "Glassfish support." - commands :asadmin => "/opt/NSBglassfish/bin/asadmin" + def self.find_asadmin(path = ENV[''PATH'']) + path.split(":").each do |directory| + executable = directory + "/asadmin" + if File.executable? executable + debug executable + return executable + end + end + return "" + end + commands :asadmin => find_asadmin def create args = [] -- Regards, Lars Tobias -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.