From 05b1414b9b40b8b6cd325ae8df7e00954fbfe695 Mon Sep 17 00:00:00 2001 From: Jens Harbott Date: Mon, 11 Dec 2017 16:06:22 +0000 Subject: [PATCH] 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 --- manifests/init.pp | 174 +++++++++++++++++++++----------- metadata.json | 2 +- templates/ethercalc.service.erb | 15 +++ 3 files changed, 130 insertions(+), 61 deletions(-) create mode 100644 templates/ethercalc.service.erb diff --git a/manifests/init.pp b/manifests/init.pp index 815a16d..48484ea 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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'], - } } diff --git a/metadata.json b/metadata.json index 7611a3a..c70d65b 100644 --- a/metadata.json +++ b/metadata.json @@ -10,6 +10,6 @@ "dependencies": [ {"name":"openstackinfra/httpd"}, {"name":"openstackinfra/redis"}, - {"name":"voxpupuli/nodejs"} + {"name":"puppet/nodejs"} ] } diff --git a/templates/ethercalc.service.erb b/templates/ethercalc.service.erb new file mode 100644 index 0000000..d3e7540 --- /dev/null +++ b/templates/ethercalc.service.erb @@ -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