2017-01-19 15:59:56 -08:00
|
|
|
# == Class: ethercalc
|
2012-10-30 16:22:20 -04:00
|
|
|
#
|
2017-01-19 15:59:56 -08:00
|
|
|
# Class to install ethercalc.
|
2012-05-07 16:03:24 +00:00
|
|
|
#
|
2017-01-19 15:59:56 -08:00
|
|
|
# To use ethercalc you will want the following includes:
|
|
|
|
# include ethercalc
|
|
|
|
# include ethercalc::redis # necessary to use mysql as the backend
|
|
|
|
# include ethercalc::site # configures ethercalc instance
|
|
|
|
# include ethercalc::apache # will add reverse proxy on localhost
|
2012-05-07 16:03:24 +00:00
|
|
|
# The defaults for all the classes should just work (tm)
|
|
|
|
#
|
|
|
|
#
|
2017-01-19 15:59:56 -08:00
|
|
|
class ethercalc (
|
|
|
|
$base_install_dir = '/opt/ethercalc',
|
2016-03-21 11:45:51 +03:00
|
|
|
$base_log_dir = '/var/log',
|
2017-01-19 15:59:56 -08:00
|
|
|
$ethercalc_user = 'ethercalc',
|
|
|
|
$ethercalc_version= '0.20161220.1',
|
2017-12-11 16:06:22 +00:00
|
|
|
# If set to system will install system package, otherwise
|
|
|
|
# we try to choose one based on the host platform
|
|
|
|
$nodejs_version = undef,
|
2012-05-07 16:03:24 +00:00
|
|
|
) {
|
|
|
|
|
2017-01-19 15:59:56 -08:00
|
|
|
$path = '/usr/local/bin:/usr/bin:/bin'
|
2013-04-08 11:20:16 -04:00
|
|
|
|
2017-12-11 16:06:22 +00:00
|
|
|
# For trusty default to upstart, node 4.x. For Xenial onwards use
|
|
|
|
# node 6.x for updated dependencies and the default systemd service
|
|
|
|
# file
|
|
|
|
case $::operatingsystem {
|
|
|
|
'Ubuntu': {
|
2018-08-09 21:06:15 +02:00
|
|
|
if versioncmp($::operatingsystemrelease, '14.04') <= 0 {
|
2017-12-11 16:06:22 +00:00
|
|
|
$use_upstart = true
|
|
|
|
if ! $nodejs_version {
|
|
|
|
$use_nodejs_version = '4.x'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ! $nodejs_version {
|
|
|
|
$use_nodejs_version = '6.x'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
# TODO(ianw) -- not sure this is a sane default, but it's the
|
|
|
|
# way it was...
|
|
|
|
if ! $nodejs_version {
|
|
|
|
$use_nodejs_version = '4.x'
|
|
|
|
} else {
|
|
|
|
$use_nodejs_version = $nodejs_version
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-19 15:59:56 -08:00
|
|
|
group { $ethercalc_user:
|
|
|
|
ensure => present,
|
2012-05-07 16:03:24 +00:00
|
|
|
}
|
|
|
|
|
2017-01-19 15:59:56 -08:00
|
|
|
user { $ethercalc_user:
|
|
|
|
shell => '/usr/sbin/nologin',
|
|
|
|
home => $base_install_dir,
|
|
|
|
system => true,
|
|
|
|
gid => $ethercalc_user,
|
|
|
|
require => Group[$ethercalc_user],
|
2012-05-07 16:03:24 +00:00
|
|
|
}
|
|
|
|
|
2012-10-30 16:22:20 -04:00
|
|
|
file { $base_install_dir:
|
2012-05-07 16:03:24 +00:00
|
|
|
ensure => directory,
|
2017-01-19 15:59:56 -08:00
|
|
|
owner => $ethercalc_user,
|
|
|
|
group => $ethercalc_user,
|
2012-10-30 16:22:20 -04:00
|
|
|
mode => '0664',
|
2012-05-07 16:03:24 +00:00
|
|
|
}
|
|
|
|
|
2017-08-24 13:46:04 -07:00
|
|
|
if !defined(Package['curl']) {
|
|
|
|
package { 'curl':
|
|
|
|
ensure => present,
|
|
|
|
}
|
2016-11-14 17:49:15 -08:00
|
|
|
}
|
|
|
|
|
2017-12-11 16:06:22 +00:00
|
|
|
file { "${base_log_dir}/${ethercalc_user}":
|
|
|
|
ensure => directory,
|
|
|
|
owner => $ethercalc_user,
|
|
|
|
}
|
|
|
|
|
2016-11-14 18:43:23 -08:00
|
|
|
anchor { 'nodejs-package-install': }
|
2012-05-07 16:03:24 +00:00
|
|
|
|
2017-12-11 16:06:22 +00:00
|
|
|
if ($use_nodejs_version != 'system') {
|
2016-11-14 18:43:23 -08:00
|
|
|
class { '::nodejs':
|
2018-07-24 11:25:53 +02:00
|
|
|
repo_url_suffix => $use_nodejs_version,
|
|
|
|
legacy_debian_symlinks => false,
|
|
|
|
before => Anchor['nodejs-package-install'],
|
2015-08-19 15:26:19 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
package { ['nodejs', 'npm']:
|
|
|
|
ensure => present,
|
2016-11-14 18:43:23 -08:00
|
|
|
before => Anchor['nodejs-package-install'],
|
2015-08-19 15:26:19 -07:00
|
|
|
}
|
2016-11-14 18:43:23 -08:00
|
|
|
}
|
2015-08-19 15:26:19 -07:00
|
|
|
|
2017-01-19 15:59:56 -08:00
|
|
|
exec { 'install-ethercalc':
|
|
|
|
command => "npm install ethercalc@${ethercalc_version}",
|
2017-02-13 17:44:43 -08:00
|
|
|
unless => "npm ls | grep ethercalc@${ethercalc_version}",
|
2017-01-19 15:59:56 -08:00
|
|
|
path => $path,
|
|
|
|
cwd => $base_install_dir,
|
2017-12-11 16:06:22 +00:00
|
|
|
require => Anchor['nodejs-package-install'],
|
2012-05-07 16:03:24 +00:00
|
|
|
}
|
|
|
|
|
2018-07-24 11:26:12 +02:00
|
|
|
# NOTE(cmurphy) Workaround global install issue
|
|
|
|
# https://github.com/audreyt/ethercalc/issues/542
|
|
|
|
if ($use_nodejs_version == '6.x') {
|
|
|
|
file { "${base_install_dir}/node_modules/ethercalc/node_modules":
|
|
|
|
ensure => directory,
|
|
|
|
require => [File[$base_install_dir], Exec['install-ethercalc']],
|
|
|
|
}
|
|
|
|
file { "${base_install_dir}/node_modules/ethercalc/node_modules/socialcalc":
|
|
|
|
ensure => link,
|
|
|
|
target => "${base_install_dir}/node_modules/socialcalc",
|
|
|
|
require => File["${base_install_dir}/node_modules/ethercalc/node_modules"],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-11 16:06:22 +00:00
|
|
|
# TODO(ianw): remove this when trusty is dropped
|
|
|
|
if $use_upstart {
|
2012-05-07 16:03:24 +00:00
|
|
|
|
2017-12-11 16:06:22 +00:00
|
|
|
file { '/etc/init/ethercalc.conf':
|
|
|
|
ensure => present,
|
|
|
|
content => template('ethercalc/upstart.erb'),
|
|
|
|
replace => true,
|
|
|
|
owner => 'root',
|
|
|
|
require => Exec['install-ethercalc'],
|
|
|
|
}
|
2012-05-07 16:03:24 +00:00
|
|
|
|
2017-12-11 16:06:22 +00:00
|
|
|
file { '/etc/init.d/ethercalc':
|
|
|
|
ensure => link,
|
|
|
|
target => '/lib/init/upstart-job'
|
|
|
|
}
|
2017-01-19 15:59:56 -08:00
|
|
|
|
2017-12-11 16:06:22 +00:00
|
|
|
service { 'ethercalc':
|
|
|
|
ensure => running,
|
|
|
|
enable => true,
|
|
|
|
require => File['/etc/init/ethercalc.conf'],
|
|
|
|
}
|
2017-01-19 15:59:56 -08:00
|
|
|
|
2017-12-11 16:06:22 +00:00
|
|
|
include ::logrotate
|
|
|
|
logrotate::file { 'ethercalc_error':
|
|
|
|
log => "${base_log_dir}/${ethercalc_user}/error.log",
|
|
|
|
options => [
|
|
|
|
'compress',
|
|
|
|
'copytruncate',
|
|
|
|
'missingok',
|
|
|
|
'rotate 7',
|
|
|
|
'daily',
|
|
|
|
'notifempty',
|
|
|
|
],
|
|
|
|
require => Service['ethercalc'],
|
|
|
|
}
|
|
|
|
|
|
|
|
logrotate::file { 'ethercalc_access':
|
|
|
|
log => "${base_log_dir}/${ethercalc_user}/access.log",
|
|
|
|
options => [
|
|
|
|
'compress',
|
|
|
|
'copytruncate',
|
|
|
|
'missingok',
|
|
|
|
'rotate 7',
|
|
|
|
'daily',
|
|
|
|
'notifempty',
|
|
|
|
],
|
|
|
|
require => Service['ethercalc'],
|
|
|
|
}
|
2017-01-19 15:59:56 -08:00
|
|
|
|
2017-12-11 16:06:22 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
# Note logs go to syslog, can maybe change when
|
|
|
|
# https://github.com/systemd/systemd/pull/7198 is available
|
|
|
|
file { '/etc/systemd/system/ethercalc.service':
|
|
|
|
ensure => present,
|
|
|
|
content => template('ethercalc/ethercalc.service.erb'),
|
|
|
|
replace => true,
|
|
|
|
owner => 'root',
|
|
|
|
require => Exec['install-ethercalc'],
|
|
|
|
}
|
|
|
|
|
|
|
|
# This is a hack to make sure that systemd is aware of the new service
|
|
|
|
# before we attempt to start it.
|
|
|
|
exec { 'ethercalc-systemd-daemon-reload':
|
|
|
|
command => '/bin/systemctl daemon-reload',
|
|
|
|
before => Service['ethercalc'],
|
|
|
|
subscribe => File['/etc/systemd/system/ethercalc.service'],
|
|
|
|
refreshonly => true,
|
|
|
|
}
|
|
|
|
|
|
|
|
service { 'ethercalc':
|
|
|
|
ensure => running,
|
|
|
|
enable => true,
|
|
|
|
require => File['/etc/systemd/system/ethercalc.service'],
|
|
|
|
}
|
2012-05-07 16:03:24 +00:00
|
|
|
}
|
2017-12-11 16:06:22 +00:00
|
|
|
|
|
|
|
|
2012-05-07 16:03:24 +00:00
|
|
|
}
|