Update ethercalc to work with Ubuntu Xenial

- Set up service via systemd instead of upstart.
 - defupalt to using nodejs v6.x because of library issues.
 - upstream nodejs puppet knows how to do legacy symlinks on required
   platforms.

Depends-On: I2355cf58c899bf5f78173b2ed9da26548a9592d0
Depends-On: Ia7966fb9578d0d79f3a7f9480e3a956555737dc8
Change-Id: Ia3f4d3bbacbbe1a42a33a4f934173fb54a582a8e
This commit is contained in:
Jens Harbott 2017-12-11 16:06:22 +00:00 committed by Colleen Murphy
parent 785e18decb
commit 05b1414b9b
3 changed files with 130 additions and 61 deletions

View File

@ -15,12 +15,41 @@ class ethercalc (
$base_log_dir = '/var/log',
$ethercalc_user = 'ethercalc',
$ethercalc_version= '0.20161220.1',
# If set to system will install system package.
$nodejs_version = 'node_4.x',
# If set to system will install system package, otherwise
# we try to choose one based on the host platform
$nodejs_version = undef,
) {
$path = '/usr/local/bin:/usr/bin:/bin'
# 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': {
if $::operatingsystemrelease <= '14.04' {
$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
}
}
}
group { $ethercalc_user:
ensure => present,
}
@ -46,11 +75,16 @@ class ethercalc (
}
}
file { "${base_log_dir}/${ethercalc_user}":
ensure => directory,
owner => $ethercalc_user,
}
anchor { 'nodejs-package-install': }
if ($nodejs_version != 'system') {
if ($use_nodejs_version != 'system') {
class { '::nodejs':
repo_url_suffix => $nodejs_version,
repo_url_suffix => $use_nodejs_version,
before => Anchor['nodejs-package-install'],
}
} else {
@ -60,70 +94,90 @@ class ethercalc (
}
}
file { '/usr/local/bin/node':
ensure => link,
target => '/usr/bin/nodejs',
require => Anchor['nodejs-package-install'],
before => Anchor['nodejs-anchor'],
}
anchor { 'nodejs-anchor': }
exec { 'install-ethercalc':
command => "npm install ethercalc@${ethercalc_version}",
unless => "npm ls | grep ethercalc@${ethercalc_version}",
path => $path,
cwd => $base_install_dir,
require => Anchor['nodejs-anchor'],
require => Anchor['nodejs-package-install'],
}
file { '/etc/init/ethercalc.conf':
ensure => present,
content => template('ethercalc/upstart.erb'),
replace => true,
owner => 'root',
# TODO(ianw): remove this when trusty is dropped
if $use_upstart {
file { '/etc/init/ethercalc.conf':
ensure => present,
content => template('ethercalc/upstart.erb'),
replace => true,
owner => 'root',
require => Exec['install-ethercalc'],
}
file { '/etc/init.d/ethercalc':
ensure => link,
target => '/lib/init/upstart-job'
}
service { 'ethercalc':
ensure => running,
enable => true,
require => File['/etc/init/ethercalc.conf'],
}
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'],
}
} 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'],
}
}
file { '/etc/init.d/ethercalc':
ensure => link,
target => '/lib/init/upstart-job',
}
file { "${base_log_dir}/${ethercalc_user}":
ensure => directory,
owner => $ethercalc_user,
}
service { 'ethercalc':
ensure => running,
enable => true,
require => File['/etc/init/ethercalc.conf'],
}
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'],
}
}

View File

@ -10,6 +10,6 @@
"dependencies": [
{"name":"openstackinfra/httpd"},
{"name":"openstackinfra/redis"},
{"name":"voxpupuli/nodejs"}
{"name":"puppet/nodejs"}
]
}

View File

@ -0,0 +1,15 @@
[Unit]
Description=ethercalc (real-time collaborative spreadsheet editing)
After=syslog.target network.target
[Service]
Type=simple
User=<%= @ethercalc_user %>
Group=<%= @ethercalc_user %>
ExecStart=/bin/bash <%= @base_install_dir %>/node_modules/ethercalc/bin/run.sh
LimitNOFILE=8192:16384
StandardOutput=syslog
StandardError=syslog
[Install]
WantedBy=multi-user.target