summaryrefslogtreecommitdiff
path: root/manifests/init.pp
blob: f8b199bd2f0376fdec7a280d82fd7b9711bc3ee4 (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
class etherpad(
  $db_password    = hiera('etherpad::db_password', ''),
  $admin_password = hiera('etherpadd::admin_password', ''),
  $api_key        = hiera('etherpad::api_key, '')
) {

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

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

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

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

  group { "etherpad-lite":
    ensure    => present,
    allowdupe => false,
  }

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

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

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

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

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

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

  file { '/etc/logrotate.d/etherpad-lite':
    ensure  => present,
    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  => present,
    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  => present,
      owner   => 'etherpad-lite',
      group   => 'etherpad-lite',
      mode    => 0640,
      content => "${api_key}",
      require => Vcsrepo['/var/lib/etherpad-lite'],
      notify  => Service['etherpad-lite'],
    }
  }

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