Puppet Service Configuration Example


1) Ensure service is always running

node “UT-9c8e99e3959e”{
service { “cron”:
        enable => true,
        ensure => “running”,
        }
}
 
Example:
generic@UT-9c8e99e3959e:~$ sudo service cron status
cron stop/waiting
generic@UT-9c8e99e3959e:~$ sudo puppet agent –test
info: Caching catalog for ut-9c8e99e3959e
info: Applying configuration version ‘1362528911’
notice: /Stage[main]//Node[ut-9c8e99e3959e]/Service[cron]/ensure: ensure changed ‘stopped’ to ‘running’
notice: Finished catalog run in 0.07 seconds
generic@UT-9c8e99e3959e:~$ sudo service cron status
cron start/running, process 31447
2) Ensure service is always stopped
 
node “UT-9c8e99e3959e”{
service { “cron”:
        enable => false,
        ensure => “stopped”,
        }
}
Example:
generic@UT-9c8e99e3959e:~$ initctl show-config cron
cron
  start on runlevel [2345]
  stop on runlevel [!2345]
generic@UT-9c8e99e3959e:~$ service cron status
cron start/running, process 5639
generic@UT-9c8e99e3959e:~$ sudo puppet agent –test
info: Caching catalog for ut-9c8e99e3959e
info: Applying configuration version ‘1362538327’
notice: /Stage[main]//Node[ut-9c8e99e3959e]/Service[cron]/ensure: ensure changed ‘running’ to ‘stopped’
notice: Finished catalog run in 0.16 seconds
generic@UT-9c8e99e3959e:~$ initctl show-config cron
cron
  stop on runlevel [!2345]
generic@UT-9c8e99e3959e:~$ service cron status
cron stop/waiting
3) Restart service when configuration file changes
 
node “UT-9c8e99e3959e”{
# define apache service
service { “apache2”:
        ensure  => “running”,
        enable  => “true”,
        }
# Notify apache if the config file changes
file { “/etc/apache2/sites-available/default”:
        notify  => Service[“apache2”],
        mode    => 644,
        owner   => “root”,
        group   => “root”,
        source => “puppet:///files/default”,
        backup => “main”,
        }
}
Example:
generic@UT-9c8e99e3959e:~$ sudo puppet agent –test
info: Caching catalog for ut-9c8e99e3959e
info: Applying configuration version ‘1362541114’
notice: /Stage[main]//Node[ut-9c8e99e3959e]/File[/etc/apache2/sites-available/default]/content:
— /etc/apache2/sites-available/default2013-03-06 15:13:11.974074555 +1100
+++ /tmp/puppet-file20130306-29247-1uo1l0x-02013-03-06 15:19:23.782082747 +1100
@@ -30,3 +30,10 @@
 CustomLog ${APACHE_LOG_DIR}/access.log combined
 </VirtualHost>
+<VirtualHost *:8080>
+        <Directory “/tmp”>
+                Order allow,deny
+                Allow from all
+        </Directory>
+</VirtualHost>
+
info: /Stage[main]//Node[ut-9c8e99e3959e]/File[/etc/apache2/sites-available/default]: Filebucketed /etc/apache2/sites-available/default to main with sum 1dd3f5bf7e4bd9734074e7f4bb4efa65
notice: /Stage[main]//Node[ut-9c8e99e3959e]/File[/etc/apache2/sites-available/default]/content: content changed ‘{md5}1dd3f5bf7e4bd9734074e7f4bb4efa65’ to ‘{md5}861b9ecffc31b92b0b6975a9aaf85ced’
info: /Stage[main]//Node[ut-9c8e99e3959e]/File[/etc/apache2/sites-available/default]: Scheduling refresh of Service[apache2]
notice: /Stage[main]//Node[ut-9c8e99e3959e]/Service[apache2]: Triggered ‘refresh’ from 1 events
notice: Finished catalog run in 426.88 seconds
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s