Defined Type: service::node
- Defined in:
- puppet/modules/service/manifests/node.pp
Overview
Examples
To set up a service named myservice on port 8520 and with a templated configuration, use:
service::node { 'myservice':
port => 8520,
config => template('myservice/config.yaml.erb'),
}
Likewise, you can supply the configuration directly as a hash:
service::node { 'myservice':
port => 8520,
config => {
param1 => 'val1',
param2 => $myvar
},
}
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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'puppet/modules/service/manifests/node.pp', line 66
define service::node(
$port,
$config = {},
$module = './app.js',
$entrypoint = '',
$script = 'server.js',
$git_remote = undef,
$log_level = undef,
$environment = {},
$npm_environment = [],
) {
require ::service
require ::npm
require ::npm::globals
# we do not allow empty names
unless $title and size($title) > 0 {
fail('No name for this resource given!')
}
# sanity check since a default port cannot be assigned
unless $port and $port =~ Integer {
fail('Service port must be specified and must be a number!')
}
# set up the remote URL
$remote = $git_remote ? {
undef => sprintf($::git::urlformat, "mediawiki/services/${title}"),
default => $git_remote
}
# the service's location
$dir = "${::service::root_dir}/${title}"
# the local log file name
$log_file = "${::service::log_dir}/${title}.log"
# set the log level
$loglev = $log_level ? {
undef => $::service::log_level,
default => $log_level
}
# ensure the RB port is defined for the config
$restbase_port = defined(Class['restbase']) ? {
true => $::restbase::port,
default => 7231,
}
# the repo
git::clone { $title:
directory => $dir,
remote => $remote,
}
# install the dependencies
npm::install { $dir:
directory => $dir,
environment => $npm_environment,
require => Git::Clone[$title],
}
# the service's configuration file
file { "${title}_config_yaml":
ensure => present,
owner => $::share_owner,
group => $::share_group,
mode => '0664',
path => "${dir}/config.vagrant.yaml",
content => merge_config(
template('service/node/config.yaml.erb'),
$config
),
require => Git::Clone[$title],
}
# set the log file's permissions
file { $log_file:
ensure => present,
mode => '0666',
owner => $::share_owner,
group => $::share_group,
}
# log rotation
file { "/etc/logrotate.d/${title}":
content => template('service/logrotate.erb'),
owner => 'root',
group => 'root',
mode => '0444',
}
# schedule the service for git-updates via vagrant git-update
service::gitupdate { $title:
type => 'nodejs',
update => true,
restart => true,
}
# the service definition
systemd::service { $title:
template_name => 'node',
service_params => {
subscribe => [
File["${title}_config_yaml"],
Npm::Install[$dir],
],
},
epp_template => true,
template_variables => {
title => $title,
uptitle => inline_template('<%= @title.gsub(/[^a-zA-Z0-9_]/, "_").upcase %>'),
dir => $dir,
port => $port,
script => $script,
environment => $environment
},
require => Git::Clone[$title],
}
}
|