Defined Type: ghost::blog

Defined in:
manifests/blog.pp

Summary

This class sets up a Ghost blog instance.

Overview

ghost::blog

The user and group must exist (can be created with the base class), and nodejs and npm must be installed.

It will install the latest version of Ghost. Subsequent updates can be forced by deleting the archive.

It can also daemonize the Ghost blog instance using supervisor.

Copyright 2014 Andrew Schwartzmeyer

Parameters:

  • blog (String) (defaults to: $title)

    Name of blog

  • user (String) (defaults to: 'ghost')

    Username for ghost instance to run under

  • group (String) (defaults to: 'ghost')

    Group for ghost instance to run under

  • home (Stdlib::Absolutepath) (defaults to: "/home/ghost/${title}")

    Root of Ghost instance (will be created if it does not already exist)

  • source (Stdlib::HTTPSUrl) (defaults to: 'https://ghost.org/zip/ghost-latest.zip')

    Source for ghost distribution

  • manage_npm_registry (Boolean) (defaults to: true)

    Whether or not to attempt to set the npm registry (often needed)

  • npm_registry (Stdlib::HTTPSUrl) (defaults to: 'https://registry.npmjs.org/')

    User’s npm registry

  • use_supervisor

    Use supervisor module to setup service for blog

  • autorestart (Boolean) (defaults to: true)

    Restart on crash

  • stdout_logfile (Stdlib::Absolutepath) (defaults to: "/var/log/ghost_${title}.log")

    Logfile for stdout

  • stderr_logfile (Stdlib::Absolutepath) (defaults to: "/var/log/ghost_${title}_err.log")

    Logfile for stderr

  • manage_config (Boolean) (defaults to: true)

    Manage Ghost’s config.js

  • url (Stdlib::HTTPSUrl) (defaults to: 'https://my-ghost-blog.com')

    Required URL of blog (must be unique)

  • host (String) (defaults to: '127.0.0.1')

    Host to listen on if not using socket

  • port (Integer) (defaults to: 2368)

    Port to listen on

  • socket (Variant[Boolean, Stdlib::Absolutepath]) (defaults to: false)

    Use a socket instead if true

  • transport (String) (defaults to: '')

    Mail transport

  • fromaddress (String) (defaults to: '')

    Mail from address

  • mail_options (Hash) (defaults to: {})

    Hash for mail options

  • use_supervisord (Boolean) (defaults to: true)


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
143
# File 'manifests/blog.pp', line 34

define ghost::blog(
  String $blog                                   = $title,
  String $user                                   = 'ghost',
  String $group                                  = 'ghost',
  Stdlib::Absolutepath $home                     = "/home/ghost/${title}",
  Stdlib::HTTPSUrl $source                       = 'https://ghost.org/zip/ghost-latest.zip',
  Boolean $manage_npm_registry                   = true,
  Stdlib::HTTPSUrl $npm_registry                 = 'https://registry.npmjs.org/',
  Boolean $use_supervisord                       = true, # User supervisor module to setup service for blog
  Boolean $autorestart                           = true, # Restart on crash
  Stdlib::Absolutepath $stdout_logfile           = "/var/log/ghost_${title}.log",
  Stdlib::Absolutepath $stderr_logfile           = "/var/log/ghost_${title}_err.log",
  Boolean $manage_config                         = true,
  Stdlib::HTTPSUrl $url                          = 'https://my-ghost-blog.com',
  String $host                                   = '127.0.0.1',
  Integer $port                                  = 2368,
  Variant[Boolean, Stdlib::Absolutepath] $socket = false,
  String $transport                              = '',
  String $fromaddress                            = '',
  Hash $mail_options                             = {},
) {

  Exec {
    path    => '/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin',
    user    => $user,
    cwd     => $home,
    require => File[$home],
  }

  File {
    owner   => $user,
    group   => $group,
  }

  file { $home:
    ensure  => directory,
  }

  if $manage_npm_registry {
    exec { "npm_config_set_registry_${blog}":
      command => "npm config set registry ${npm_registry}",
      unless  => "npm config get registry | grep ${npm_registry}",
      before  => Exec["npm_install_ghost_${blog}"],
    }
  }

  ensure_packages(['unzip', 'curl'])

  exec { "curl_ghost_${blog}":
    command => "curl -L ${source} -o ghost.zip",
    unless  => 'test -f ghost.zip',
    require => Package['curl'],
  }

  exec { "unzip_ghost_${blog}":
    command     => 'unzip -uo ghost.zip',
    require     => Package['unzip'],
    subscribe   => Exec["curl_ghost_${blog}"],
    refreshonly => true,
  }

  exec { "npm_install_ghost_${blog}":
    command     => 'npm install --production', # Must be --production
    subscribe   => Exec["unzip_ghost_${blog}"],
    refreshonly => true,
  }

  if $manage_config {
    file { "ghost_config_${blog}":
      path    => "${home}/config.js",
      content => template('ghost/config.js.erb'),
      require => Exec["unzip_ghost_${blog}"],
    }
  }
  else {
    # Need this file for Exec[restart_ghost_${blog}] dependency
    file { "ghost_config_${blog}":
      path    => "${home}/puppet.lock",
      content => 'Puppet: delete this file to force a restart via Puppet',
    }
  }

  if $use_supervisord {
    require supervisord

    case $facts['os']['family'] {
      'RedHat': {
        $path_bin = '/usr/bin'
      }
      'Debian': {
        $path_bin = '/usr/local/bin'
      }
      default: {
        fail("ERROR - ${facts['os']['family']} based systems are not supported!")
      }
    }

    Class['supervisord']
    -> supervisord::program { "ghost_${blog}":
      command             => "node ${home}/index.js",
      autorestart         => $autorestart,
      user                => $user,
      directory           => $home,
      stdout_logfile      => $stdout_logfile,
      stderr_logfile      => $stderr_logfile,
      program_environment => { 'NODE_ENV' => 'production' },
      notify              => Service['supervisord'],
    }
  }
}