summaryrefslogtreecommitdiff
path: root/manifests/init.pp
blob: 9dee68060b3d451dcf589b57227aebc4a6a9d568 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
class etherpad(
  $db_password    = hiera('etherpad::db_password',     ''),
  $admin_password = hiera('etherpadd::admin_password', ''),
  $api_key        = hiera('etherpad::api_key',         ''),
  $ensure         = hiera('etherpad::ensure',          'present')
) {

  case $db_password {
    '': { fail("You need to define etherpad database password! Please set etherpadd::db_password in your config") }
  }

  mysql_database { 'etherpad':
    ensure => $ensure,
  }

  mysql_user { "etherpad@%":
    ensure        => $ensure,
    password_hash => mysql_password($db_password),
    require       => Mysql_database['etherpad'],
  }

  if $ensure == 'present' {
    mysql_grant { "etherpad@%/etherpad":
      privileges => 'all',
      require    => Mysql_user["etherpad@%"],
    }
  }

  group { "etherpad-lite":
    ensure    => $ensure,
    allowdupe => false,
    require   => $ensure ? {
      present => undef,
      default => User['etherpad-lite'], # Make sure the user is removed first
    }
  }

  user { "etherpad-lite":
    ensure    => $ensure,
    allowdupe => false,
    gid       => 'etherpad-lite',
    require   => $ensure ? {
      present => Group['etherpad-lite'],
      default => undef,
    }
  }

  file { '/home/etherpad-lite':
    ensure => directory,
    owner    => 'etherpad-lite',
    group    => 'etherpad-lite',
    require  => User['etherpad-lite'],
  }

  package { [ 'npm', 'abiword' ]:
    ensure => $ensure,
  }

  vcsrepo { "/var/lib/etherpad-lite":
    ensure   => $ensure,
    provider => git,
    source   => 'https://github.com/ether/etherpad-lite.git',
    revision => '8fffe4777e366923ee89d380b12eb413c950b721',
    owner    => 'etherpad-lite',
    group    => 'etherpad-lite',
    require  => [ User['etherpad-lite'], Group['etherpad-lite'] ],
    notify   => Service['etherpad-lite'],
  }

  file { '/etc/init.d/etherpad-lite':
    ensure  => $ensure,
    owner   => root,
    group   => root,
    mode    => 0755,
    source  => 'puppet:///modules/etherpad/init.d/etherpad-lite.sh',
    require => Vcsrepo['/var/lib/etherpad-lite'],
  }

  $directory = $ensure ? {
    'present' => 'directory',
     default  => 'absent',
  }

  file { '/var/log/etherpad-lite':
    ensure  => $directory,
    owner   => 'etherpad-lite',
    group   => 'etherpad-lite',
    mode    => 0755,
    require => $ensure ? {
      present => [ User['etherpad-lite'], Group['etherpad-lite'] ],
      default => undef,
    },
  }

  file { '/etc/logrotate.d/etherpad-lite':
    ensure  => $ensure,
    owner   => root,
    group   => root,
    mode    => 0644,
    source  => 'puppet:///modules/etherpad/logrotate.d/etherpad-lite',
    require => File['/var/log/etherpad-lite'],
  }

  file { '/var/lib/etherpad-lite/settings.json':
    ensure  => $ensure,
    owner   => 'etherpad-lite',
    group   => 'etherpad-lite',
    mode    => 0640,
    content => template('etherpad/settings.json.erb'),
    require => Vcsrepo['/var/lib/etherpad-lite'],
    notify  => Service['etherpad-lite'],
  }

  if $api_key != '' {
    file { '/var/lib/etherpad-lite/APIKEY.txt':
      ensure  => $ensure,
      owner   => 'etherpad-lite',
      group   => 'etherpad-lite',
      mode    => 0640,
      content => "${api_key}",
      require => Vcsrepo['/var/lib/etherpad-lite'],
      notify  => Service['etherpad-lite'],
    }
  }

  $service = $ensure ? {
    'present' => 'running',
     default  => 'stopped',
  }

  service { 'etherpad-lite':
    enable     => true,
    ensure     => $service,
    hasrestart => true,
    hasstatus  => true,
    require    => $ensure ? {
      present => [ File['/etc/init.d/etherpad-lite', '/var/lib/etherpad-lite/settings.json',
                        '/home/etherpad-lite'], Mysql_grant['etherpad@%/etherpad'], Package['npm'] ],
      default => undef,
    },
  }
}