Update to work with Ubuntu Xenial

Changes to work with Xenial

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

Depends-On: Ia7966fb9578d0d79f3a7f9480e3a956555737dc8
Change-Id: Ia3f4d3bbacbbe1a42a33a4f934173fb54a582a8e
This commit is contained in:
Jens Harbott 2017-12-11 16:06:22 +00:00 committed by Ian Wienand
parent 31e44bbcb0
commit fd89ef3574
2 changed files with 82 additions and 28 deletions

View File

@ -16,11 +16,32 @@ class ethercalc (
$ethercalc_user = 'ethercalc',
$ethercalc_version= '0.20161220.1',
# If set to system will install system package.
$nodejs_version = 'node_4.x',
$nodejs_version = undef,
) {
$path = '/usr/local/bin:/usr/bin:/bin'
# For trusty default to upstart, node 4.x. For Xenial use node 6.x
# for updated dependencies and the default systemd service file
case $facts['os']['family'] {
'Debian': {
if $facts['os']['release']['full'] =~ /^14\.04$/ {
$use_upstart = true
if ! $nodejs_version {
$nodejs_version = 'node_4.x'
}
}
elsif $facts['os']['release']['full'] =~ /^16\.04$/ {
if ! $nodejs_version {
$nodejs_version = '6.x'
}
} else {
fail("This module is not supported on this platform")
}
}
}
group { $ethercalc_user:
ensure => present,
}
@ -50,8 +71,8 @@ class ethercalc (
if ($nodejs_version != 'system') {
class { '::nodejs':
repo_url_suffix => $nodejs_version,
before => Anchor['nodejs-package-install'],
repo_url_suffix => $nodejs_version,
before => Anchor['nodejs-package-install'],
}
} else {
package { ['nodejs', 'npm']:
@ -60,33 +81,59 @@ 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): remote this when trusty is dropped
if defined($use_upstart) {
file { '/etc/init/ethercalc.conf':
ensure => present,
content => template('ethercalc/upstart.erb')
replace => true,
owner => 'root',
}
file { '/etc/init.d/ethercalc':
ensure => link,
target => '/lib/init/upstart-job'
}
service { 'ethercalc':
ensure => running,
enable => true,
require => File['/etc/init/ethercalc.conf'],
}
} else {
file { '/etc/systemd/system/ethercalc.service':
ensure => present,
content => template('ethercalc/ethercalc.service.erb'),
replace => true,
owner => 'root',
}
# 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/init/ethercalc.conf'],
}
file { '/etc/init.d/ethercalc':
ensure => link,
target => '/lib/init/upstart-job',
}
file { "${base_log_dir}/${ethercalc_user}":
@ -94,12 +141,6 @@ class ethercalc (
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",

View File

@ -0,0 +1,13 @@
[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
[Install]
WantedBy=multi-user.target