Jesús Couto
2010-Jan-11 21:06 UTC
[Puppet Users] Recipes/modules for multiple instances of web server?
Hi. I''m trying to do a test/proof of concept of Puppet as a tool to manage our systems. In our enviroment we have several different instances of apache running on each "webserver" machine, and several instances of tomcat running in our "appservers" machines I''m trying to duplicate that structure using Puppet on a Ubuntu machine I''m using for testing, to no avail yet. Isnt any well know recipe to do this? Or at least an idea about how to go to achieve it? So far what I''ve done is this: - Define a class webserver that ensures the apache package is installed and NOT running, and creates a directory for the instances info to be stored class webserver { case $operatingsystem { ubuntu: { $web_packages = "apache2" } } package { $web_packages: ensure => installed } service { httpd: name => $operatingsystem ? { ubuntu => "apache2", }, ensure => stopped, enable => false, } file {"/etc/webinstances/": ensure => directory, owner => root, group => root, mode => 755, } } - Include that class into a definition of "webinstance" that tries to populate the directory of that instance from the puppet fileserver, and start/stop a "base" service provider with a script generated from a template: define webinstance(owner,group,ensure = running) { include webserver file { "/etc/webinstances/$name/": owner => $owner, group => $group, mode => 600, ensure => directory, recurse => true, source => "puppet:///webinstances/$name/", } file { "/usr/sbin/start_$name.sh": owner => root, group => root, mode => 700, content => template("start_instance.erb"), } file { "/usr/sbin/stop_$name.sh": owner => root, group => root, mode => 700, content => template("stop_instance.erb"), } service { "$name": ensure => $ensure, provider => base, start => "/usr/sbin/start_$name.sh", stop => "/usr/sbin/stop_$name.sh", status => "/usr/sbin/apache2 -f /etc/webinstances/$name/apache2.conf -k sta rt", require => [ File["/etc/webinstances/$name"],File["/usr/sbin/start_$name.sh "],File["/usr/sbin/stop_$name.sh"] ], } } - every node that needs to have an instance will define it node staberinde { webinstance { "uno": owner => root, group => root, ensure => running, } webinstance { "dos": owner => root, group => root, ensure => running, } } ... but appart from not getting the scripts to start & stop the instances (it says the scripts "return 1" although I can run them from the prompt without problem: err: //Node[staberinde]/Webinstance[uno]/Service[uno]/ensure: change from stopped to running failed: Could not start Service[uno]: Execution of ''/usr/sbin/start_uno.sh'' returned 1: at /etc/puppet/manifests/webinstance-definition.pp:31 ... the other thing that is making me think this is convoluted and wrong is... what if I want the same instance in 2 nodes, as we do? can I use the definition on both nodes with the same parameters and not get an error cause I''m defining the same resource twice? Best regards, ------------------------------ Jesús Couto F. -- 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.
Silviu Paragina
2010-Jan-11 22:17 UTC
Re: [Puppet Users] Recipes/modules for multiple instances of web server?
Jesús Couto wrote:> Hi. I''m trying to do a test/proof of concept of Puppet as a tool to > manage our systems.Hello, wow long mail. :)> > In our enviroment we have several different instances of apache > running on each "webserver" machine, and several instances of tomcat > running in our "appservers" machines > > I''m trying to duplicate that structure using Puppet on a Ubuntu > machine I''m using for testing, to no avail yet. > > Isnt any well know recipe to do this? Or at least an idea about how to > go to achieve it? > > So far what I''ve done is this: > > - Define a class webserver that ensures the apache package is > installed and NOT running, and creates a directory for the instances > info to be stored > > class webserver { > case $operatingsystem { > ubuntu: { $web_packages = "apache2" } > } > > package { $web_packages: ensure => installed } > > service { httpd: > name => $operatingsystem ? { > ubuntu => "apache2", > }, > ensure => stopped, > enable => false, > } > file {"/etc/webinstances/": > ensure => directory, > owner => root, > group => root, > mode => 755, > } > } > > - Include that class into a definition of "webinstance" that tries to > populate the directory of that instance from the puppet fileserver, > and start/stop a "base" service provider with a script generated from > a template: > > define webinstance(owner,group,ensure = running) { > include webserver > file { "/etc/webinstances/$name/": > owner => $owner, > group => $group, > mode => 600, > ensure => directory, > recurse => true, > source => "puppet:///webinstances/$name/", > }Sidenote: the above resource will not purge old files.> file { "/usr/sbin/start_$name.sh": > owner => root, > group => root, > mode => 700, > content => template("start_instance.erb"), > > } > file { "/usr/sbin/stop_$name.sh": > owner => root, > group => root, > mode => 700, > content => template("stop_instance.erb"), > } > service { "$name": > ensure => $ensure, > provider => base, > start => "/usr/sbin/start_$name.sh", > stop => "/usr/sbin/stop_$name.sh", > status => "/usr/sbin/apache2 -f > /etc/webinstances/$name/apache2.conf -k sta > rt", > require => [ > File["/etc/webinstances/$name"],File["/usr/sbin/start_$name.sh > "],File["/usr/sbin/stop_$name.sh"] ], > } > }This sounds sane, with the possible addition of the /etc/webinstances/$name/apache2.conf as a notify resource to restart the service> > - every node that needs to have an instance will define it > > node staberinde { > webinstance { "uno": > owner => root, > group => root, > ensure => running, > } > webinstance { "dos": > owner => root, > group => root, > ensure => running, > } > } > > ... but appart from not getting the scripts to start & stop the > instances (it says the scripts "return 1" although I can run them from > the prompt without problem: > > err: //Node[staberinde]/Webinstance[uno]/Service[uno]/ensure: change > from stopped to running failed: Could not start Service[uno]: > Execution of ''/usr/sbin/start_uno.sh'' returned 1: at > /etc/puppet/manifests/webinstance-definition.pp:31The return value of the scripts should be 0. (check for exit statements in the script) Unfortunately the scripts are the fault here and they should return 0 for success and anything else for failure, this is the way puppet figures out if everything went ok or not. To check the return value of the scripts run them and then echo $? EX: /usr/sbin/start_uno.sh echo $? Also make sure that the status is correct. (try running puppet wile the services are running, and wile not, but I guess they are not since this should install them, right?)> > ... the other thing that is making me think this is convoluted and > wrong is... what if I want the same instance in 2 nodes, as we do? can > I use the definition on both nodes with the same parameters and not > get an error cause I''m defining the same resource twice?The only problem is using the same resource twice on the same node. You can apply the same resource for each node you have if you wish. Silviu -- 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.
Dan Bode
2010-Jan-12 05:17 UTC
Re: [Puppet Users] Recipes/modules for multiple instances of web server?
On Mon, Jan 11, 2010 at 1:06 PM, Jesús Couto <jesus.couto@gmail.com> wrote:> Hi. I''m trying to do a test/proof of concept of Puppet as a tool to manage > our systems. > > In our enviroment we have several different instances of apache running on > each "webserver" machine, and several instances of tomcat running in our > "appservers" machines > > I''m trying to duplicate that structure using Puppet on a Ubuntu machine I''m > using for testing, to no avail yet. > > Isnt any well know recipe to do this? Or at least an idea about how to go > to achieve it? > > So far what I''ve done is this: > > - Define a class webserver that ensures the apache package is installed and > NOT running, and creates a directory for the instances info to be stored > > class webserver { > case $operatingsystem { > ubuntu: { $web_packages = "apache2" } > } > > package { $web_packages: ensure => installed } > > service { httpd: > name => $operatingsystem ? { > ubuntu => "apache2", > }, > ensure => stopped, > enable => false, > } > file {"/etc/webinstances/": > ensure => directory, > owner => root, > group => root, > mode => 755, > } > } > > - Include that class into a definition of "webinstance" that tries to > populate the directory of that instance from the puppet fileserver, and > start/stop a "base" service provider with a script generated from a > template: > > define webinstance(owner,group,ensure = running) { > include webserver > file { "/etc/webinstances/$name/": > owner => $owner, > group => $group, > mode => 600, > ensure => directory, > recurse => true, > source => "puppet:///webinstances/$name/", > } > file { "/usr/sbin/start_$name.sh": > owner => root, > group => root, > mode => 700, > content => template("start_instance.erb"), > > } > file { "/usr/sbin/stop_$name.sh": > owner => root, > group => root, > mode => 700, > content => template("stop_instance.erb"), > } > service { "$name": > ensure => $ensure, > provider => base, > start => "/usr/sbin/start_$name.sh", > stop => "/usr/sbin/stop_$name.sh", > status => "/usr/sbin/apache2 -f > /etc/webinstances/$name/apache2.conf -k sta > rt", > require => [ > File["/etc/webinstances/$name"],File["/usr/sbin/start_$name.sh > "],File["/usr/sbin/stop_$name.sh"] ], > } > } > > - every node that needs to have an instance will define it > > node staberinde { > webinstance { "uno": > owner => root, > group => root, > ensure => running, > } > webinstance { "dos": > owner => root, > group => root, > ensure => running, > } > } > > ... but appart from not getting the scripts to start & stop the instances > (it says the scripts "return 1" although I can run them from the prompt > without problem: > > err: //Node[staberinde]/Webinstance[uno]/Service[uno]/ensure: change from > stopped to running failed: Could not start Service[uno]: Execution of > ''/usr/sbin/start_uno.sh'' returned 1: at > /etc/puppet/manifests/webinstance-definition.pp:31 > > the start and stop params take a command, not a file. (just like status)You are executing the filename as a command, which will return 1. If you want to use a file, then use a file to create custom init scripts, in redhat (and I think on Debian, it looks like this) file { "/etc/init.d/$name": owner => root, group => root, mode => 700, content => template("start_instance.erb"), } service{$name ensure => running, status => "/usr/sbin/apache2 -f /etc/webinstances/$name/> > apache2.conf -k sta > rt", > require => [ > File["/etc/webinstances/$name"],File["/usr/sbin/start_$name.sh > "],File["/etc/init.d/$name."] ],} the script woudl have to be a little different (ie: take stop and start as arguments like regular init script)> ... the other thing that is making me think this is convoluted and wrong > is... what if I want the same instance in 2 nodes, as we do? can I use the > definition on both nodes with the same parameters and not get an error cause > I''m defining the same resource twice? >You can specify the same resources on multiple nodes. Resources must be unique per compiled catalog. Only resources for a certain host will be compiled into its catalog.> > Best regards, > > ------------------------------ > > Jesús Couto F. > > -- > 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<puppet-users%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > >-- 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.
Jesús Couto
2010-Jan-12 09:12 UTC
Re: [Puppet Users] Recipes/modules for multiple instances of web server?
> > the start and stop params take a command, not a file. (just like status) > You are executing the filename as a command, which will return 1. > >No, thats the idea, to execute them. Those last files are scripts to start & stop the instances. I also thought the solution you mention, to create the init.d scripts so I use a service with, say, the debian provider. But I fixed the problem, now it executes the scripts and starts the services. Doesnt stop them but that seems to be something else :-(> You can specify the same resources on multiple nodes. > > Resources must be unique per compiled catalog. Only resources for a certain > host will be compiled into its catalog. >Hmmm... that clears it a lot, thanks! Best regards, -- ------------------------------ Jesús Couto F. -- 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.
Dan Bode
2010-Jan-12 13:49 UTC
Re: [Puppet Users] Recipes/modules for multiple instances of web server?
On Tue, Jan 12, 2010 at 1:12 AM, Jesús Couto <jesus.couto@gmail.com> wrote:> > >> the start and stop params take a command, not a file. (just like status) >> You are executing the filename as a command, which will return 1. >> >> > No, thats the idea, to execute them. Those last files are scripts to start > & stop the instances. I also thought the solution you mention, to create the > init.d scripts so I use a service with, say, the debian provider. But I > fixed the problem, now it executes the scripts and starts the services. > Doesnt stop them but that seems to be something else :-( > >can you share the contents of the init script? does it have a #!/bin/bash statement? can you try executing with bash start => ''bash /tmp/command.sh''> > > >> You can specify the same resources on multiple nodes. >> >> Resources must be unique per compiled catalog. Only resources for a >> certain host will be compiled into its catalog. >> > > Hmmm... that clears it a lot, thanks! > > Best regards, > > -- > ------------------------------ > > Jesús Couto F. > > -- > 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<puppet-users%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > >-- 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.
Jesús Couto
2010-Jan-12 14:04 UTC
Re: [Puppet Users] Recipes/modules for multiple instances of web server?
On Tue, Jan 12, 2010 at 2:49 PM, Dan Bode <dan@reductivelabs.com> wrote:> > > On Tue, Jan 12, 2010 at 1:12 AM, Jesús Couto <jesus.couto@gmail.com>wrote: > >> >> >>> the start and stop params take a command, not a file. (just like status) >>> You are executing the filename as a command, which will return 1. >>> >>> >> No, thats the idea, to execute them. Those last files are scripts to start >> & stop the instances. I also thought the solution you mention, to create the >> init.d scripts so I use a service with, say, the debian provider. But I >> fixed the problem, now it executes the scripts and starts the services. >> Doesnt stop them but that seems to be something else :-( >> >> > can you share the contents of the init script? does it have a #!/bin/bash > statement? can you try executing with bash > >its this ERB template #!/bin/bash . /etc/webinstances/<%= name %>/envvars /usr/sbin/apache2 -f /etc/webinstances/<%= name %>/apache2.conf -k start As you see, very simple. And now it works cause the apache2 line was having output, that was what was making it not run. I''m not sure why the stop script is not being invoked when I say ensure => stopped - I think it has to do with not finding the status line on the ps listing? What would be the advantage of running it by calling bash? ------------------------------ Jesús Couto F. -- 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.
Jesús Couto
2010-Jan-12 15:24 UTC
Re: [Puppet Users] Recipes/modules for multiple instances of web server?
BTW, what is the necessary output for the status command on a base service provider to make puppet realize the service is up or not? Cause right now it ALWAYS find that the service is not running, with a small script like this: #!/bin/bash . /etc/webinstances/uno/envvars if [ -f $APACHE_PID_FILE ]; then echo "Running:("`cat $APACHE_PID_FILE`")" else echo "Not Running" fi Best regards, ------------------------------ Jesús Couto F. -- 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.
Scott Smith
2010-Jan-12 16:51 UTC
Re: [Puppet Users] Recipes/modules for multiple instances of web server?
On 1/12/10 7:24 AM, Jesús Couto wrote:> BTW, what is the necessary output for the status command on a base > service provider to make puppet realize the service is up or not? Cause > right now it ALWAYS find that the service is not running, with a small > script like this: >Looking at other init scripts, I would make a guess at the return code of the script. You can always browse the Puppet source for the init provider and see for yourself, though. You learn more that way :) -scott --00504502cbfd17bcf7047cfa7896 Content-Type: text/plain; charset=ISO-8859-1 -- 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. --00504502cbfd17bcf7047cfa7896--
Peter Meier
2010-Jan-12 17:08 UTC
Re: [Puppet Users] Recipes/modules for multiple instances of web server?
> Looking at other init scripts, I would make a guess at the return > code of the script. You can always browse the Puppet source for the > init provider and see for yourself, though. You learn more that way :)it is the exit code. cheers pete -- 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.