Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Minimal manageent of rclocal based on scripts in rc.local.d

  • Loading branch information...
commit 702a9d5a312c5c7d9eafc1cbf48610b450830524 0 parents
@alvagante alvagante authored
33 manifests/init.pp
@@ -0,0 +1,33 @@
+# Class: rclocal
+#
+# Manages /etc/rc.local file inserting a /etc/rc.local.d/ directory where
+# each script is managaed by Puppet
+#
+# Usage:
+# include rclocal
+#
+class rclocal {
+
+ # Load the variables used in this module. Check the params.pp file
+ require rclocal::params
+
+ file { '/etc/rc.local':
+ ensure => present,
+ path => $rclocal::params::configfile,
+ mode => '0755',
+ owner => 'root',
+ group => 'root',
+ content => template('rclocal/rc.local.erb'),
+ }
+
+ file { '/etc/rc.local.d':
+ path => $rclocal::params::configdir,
+ mode => '0755',
+ owner => 'root',
+ group => 'root',
+ ensure => directory,
+ purge => true,
+ recurse => true,
+ }
+
+}
19 manifests/params.pp
@@ -0,0 +1,19 @@
+# Class: rclocal::params
+#
+# Sets internal variables and defaults for rclocal module
+# This class is automatically loaded in all the classes that use the values set here
+#
+class rclocal::params {
+
+## MODULE INTERNAL VARIABLES
+# (Modify to adapt to unsupported OSes)
+
+ $configfile = $::osfamily ? {
+ RedHat => '/etc/rc.d/rc.local',
+ default => '/etc/rc.local',
+ }
+
+ $configdir = $::operatingsystem ? {
+ default => '/etc/rc.local.d',
+ }
+}
44 manifests/script.pp
@@ -0,0 +1,44 @@
+# Define rclocal::script
+#
+# This define creates a single script in /etc/rc.local/.d that is executed by /etc/rc.local at boot time
+#
+# Usage:
+# rclocal::script { "set_route":
+# priority => "10",
+# content => "route add -net 10.42.0.0/24 gw 10.42.10.1 \n",
+# }
+#
+# Priority influences the execution order while content contains the script
+# to be executed. Can be also a template, had has the saem syntax of the
+# content param in the file type.
+#
+define rclocal::script (
+ $priority = '50',
+ $autoexec = true,
+ $content = '' ) {
+
+ include rclocal
+ require rclocal::params
+
+ $safe_name = regsubst($name, '/', '_', 'G')
+ $bool_autoexec = any2bool($autoexec)
+
+ file { "rclocal_${priority}_${safe_name}":
+ path => "${rclocal::params::configdir}/${priority}-${safe_name}",
+ mode => '0755',
+ owner => 'root',
+ group => 'root',
+ require => File['/etc/rc.local.d'],
+ content => $content,
+ }
+
+ if $bool_autoexec == true {
+ exec { "rclocal_${priority}_${safe_name}":
+ command => "sh ${rclocal::params::configdir}/${priority}-${safe_name}",
+ refreshonly => true,
+ subscribe => File[ "rclocal_${priority}_${safe_name}" ],
+ path => '/usr/bin:/bin:/usr/sbin:/sbin',
+ }
+ }
+}
+
19 templates/rc.local.erb
@@ -0,0 +1,19 @@
+#!/bin/sh -e
+# File Managed by Puppet
+#
+# This script is executed at the end of each multiuser runlevel.
+# Make sure that the script will "exit 0" on success or any other
+# value on error.
+#
+# With Puppet is managed the content of <%= scope.lookupvar('rclocal::params::configdir') %>
+
+for command in $(ls -v1 <%= scope.lookupvar('rclocal::params::configdir') %> ) ; do
+ <%= scope.lookupvar('rclocal::params::configdir') %>/$command
+done
+
+<% if osfamily == 'RedHat' %>
+touch /var/lock/subsys/local
+<% end %>
+<% if osfamily == 'Debian' %>
+exit 0
+<% end %>
Please sign in to comment.
Something went wrong with that request. Please try again.