summaryrefslogtreecommitdiff
path: root/manifests/daemon.pp
blob: 1102398c8926f48d1d190033a41947108c5590eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# handles puppetd service
class puppet::daemon(
  $master        = false,
  $main_master   = false,
  $ensure        = hiera('puppet::daemon::ensure',       ''),
  $port          = hiera('puppet::daemon::port',         "8140"),
  $runinterval   = hiera('puppet::daemon::runinterval',  "7200"),
  $configtimeout = hiera('puppet::daemon::configtimeout', "120"),
  $server        = hiera('puppet::daemon::server',        "puppet.${::domain}")
) {
  include puppet

  case $ensure {
    '': {
      $daemon_ensure = $::lsbdistcodename ? {
        'squeeze' => '2.7.18-1~bpo60+1',
        default   => installed,
      }
    }
  }

  package { "puppet-common":
    ensure => $daemon_ensure,
  }

  package { "puppet":
   ensure  => $daemon_ensure,
   require => Package["cron", "puppet-common"],
  }

  file { "/etc/default/puppet":
    source => "puppet:///modules/puppet/puppet",
    owner  => "root",
    group  => "root",
    mode   => 0644,
    ensure => present,
    notify => Service["puppet"],
  }

  service { "puppet":
    enable     => true,
    ensure     => running,
    hasrestart => true,
    require    => [ Package["puppet"], File["/etc/default/puppet"] ],
  }

  # Name of puppet agent section in config file
  if $::puppetversion <= "0.25.4" {
    $agent_name = 'puppetd'
  } else {
    $agent_name = 'agent'
  }

  # Default config file for puppet nodes
  if ($master != true) or ($main_master != true) {
    file { "/etc/puppet/puppet.conf":
      ensure  => file,
      owner   => puppet,
      group   => puppet,
      content => template("puppet/puppet-node.conf.erb"),
    }
  } else {
    file { "/etc/puppet/puppet.conf":
      ensure  => file,
      owner   => puppet,
      group   => puppet,
    }
  }

  # Cron rule to restart puppet minutes after puppetmaster is restarted
  cron { "puppet-restart":
    command  => "/etc/init.d/puppet restart > /dev/null 2>&1",
    user     => root,
    hour     => "*/1",
    minute   => "10",
    ensure   => absent,
    require  => Service["puppet"],
  }

  file { "/usr/local/sbin/check-puppetd.sh":
    content => template("puppet/check-puppetd.sh.erb"),
    owner   => "puppet",
    group   => "puppet",
    mode    => 0755,
    ensure  => present,
  }

  cron { "puppetd-check":
    command  => "/usr/local/sbin/check-puppetd.sh > /dev/null",
    user     => root,
    hour     => "*/1",
    minute   => "0",
    require  => File["/usr/local/sbin/check-puppetd.sh"],
    ensure   => present,
  }

  # Thanks to https://labs.riseup.net/code/projects/shared-puppet
  file { "/etc/cron.d/puppetd":
    source => "puppet:///modules/puppet/cron.d/puppetd",
    owner  => root,
    group  => root,
    mode   => 0644;
  }

  # Restore to original state after the following bug is addressed:
  # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=625626
  if $::lsbdistcodename == 'squeeze' {
    file { "/etc/logrotate.d/puppetmaster":
      ensure => absent,
    }
  }
}