init.pp 2.36 KB
Newer Older
intrigeri's avatar
intrigeri committed
1
class bitcoind(
2
  $daemon_args     = '-daemon',
intrigeri's avatar
intrigeri committed
3
  $systemd_daemon_args = '-server',
4
5
6
7
  $rpcuser         = '',
  $rpcpassword     = '',
  $ensure          = 'running',
  $maxconnections  = 25,
8
9
  $server          = true,
  $proxy           = false,
10
  $addnodes        = [],
intrigeri's avatar
intrigeri committed
11
  $paytxfee        = false,
12
  $txconfirmtarget = 1,
13
  Boolean $prune   = false,
Silvio Rhatto's avatar
Silvio Rhatto committed
14
) {
intrigeri's avatar
Lint.    
intrigeri committed
15
16
  if $rpcuser == '' {
    fail('You need to define a login for the JSON-RPC API! Please set bitcoind::rpcuser in your config')
Silvio Rhatto's avatar
Silvio Rhatto committed
17
18
  }

intrigeri's avatar
Lint.    
intrigeri committed
19
20
  if $rpcpassword == '' {
    fail('You need to define a password for the JSON-RPC API! Please set bitcoind::rpcpassword in your config')
Silvio Rhatto's avatar
Silvio Rhatto committed
21
  }
intrigeri's avatar
intrigeri committed
22

Silvio Rhatto's avatar
Silvio Rhatto committed
23
  package { 'bitcoind':
24
    ensure => latest,
Silvio Rhatto's avatar
Silvio Rhatto committed
25
26
  }

intrigeri's avatar
intrigeri committed
27
  group { 'bitcoin':
Silvio Rhatto's avatar
Silvio Rhatto committed
28
29
30
31
    ensure    => present,
    allowdupe => false,
  }

intrigeri's avatar
intrigeri committed
32
  user { 'bitcoin':
33
34
35
36
37
38
39
    ensure         => present,
    allowdupe      => false,
    shell          => '/bin/bash',
    gid            => bitcoin,
    home           => '/var/lib/bitcoin',
    require        => Group['bitcoin'],
    purge_ssh_keys => true,
Silvio Rhatto's avatar
Silvio Rhatto committed
40
41
42
  }

  file { '/var/lib/bitcoin':
intrigeri's avatar
intrigeri committed
43
44
45
46
47
    ensure  => directory,
    owner   => bitcoin,
    group   => bitcoin,
    mode    => '0750',
    require => User[bitcoin],
Silvio Rhatto's avatar
Silvio Rhatto committed
48
49
  }

Silvio Rhatto's avatar
Silvio Rhatto committed
50
  file { '/var/lib/bitcoin/.bitcoin':
intrigeri's avatar
intrigeri committed
51
52
53
54
55
    ensure  => directory,
    owner   => bitcoin,
    group   => bitcoin,
    mode    => '0750',
    require => File['/var/lib/bitcoin'],
Silvio Rhatto's avatar
Silvio Rhatto committed
56
57
58
59
  }

  file { '/var/lib/bitcoin/.bitcoin/bitcoin.conf':
    ensure  => present,
intrigeri's avatar
intrigeri committed
60
61
62
    owner   => bitcoin,
    group   => bitcoin,
    mode    => '0600',
Silvio Rhatto's avatar
Silvio Rhatto committed
63
    content => template('bitcoind/bitcoin.conf.erb'),
Silvio Rhatto's avatar
Silvio Rhatto committed
64
    require => File['/var/lib/bitcoin/.bitcoin'],
intrigeri's avatar
intrigeri committed
65
    notify  => Service[bitcoind],
Silvio Rhatto's avatar
Silvio Rhatto committed
66
67
  }

Silvio Rhatto's avatar
Silvio Rhatto committed
68
  file { '/etc/init.d/bitcoind':
69
    ensure  => absent,
Silvio Rhatto's avatar
Silvio Rhatto committed
70
71
  }

intrigeri's avatar
intrigeri committed
72
73
74
75
76
77
78
79
80
  file { '/etc/systemd/system/bitcoind.service':
    ensure  => present,
    owner   => root,
    group   => root,
    mode    => '0644',
    content => template('bitcoind/bitcoind.service.erb'),
    notify  => Service['bitcoind'],
  }

81
  $enable = $ensure ? {
intrigeri's avatar
intrigeri committed
82
83
    running => true,
    default => false,
84
85
  }

86
87
88
89
90
91
92
93
94
95
96
  service { 'bitcoind':
    ensure     => $ensure,
    enable     => $enable,
    provider   => systemd,
    hasrestart => true,
    hasstatus  => true,
    require    => [
      Package[bitcoind],
      File[
        '/var/lib/bitcoin/.bitcoin/bitcoin.conf',
        '/etc/systemd/system/bitcoind.service'
intrigeri's avatar
intrigeri committed
97
      ],
98
99
    ],
    subscribe  => File['/etc/systemd/system/bitcoind.service'],
Silvio Rhatto's avatar
Silvio Rhatto committed
100
  }
intrigeri's avatar
intrigeri committed
101

Silvio Rhatto's avatar
Silvio Rhatto committed
102
}