diff --git a/manifests/init.pp b/manifests/init.pp index 815a16d..22e64ba 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -16,11 +16,38 @@ 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') + } + } + default: { + # TODO(ianw) -- not sure this is a sane default, but it's the + # way it was... + if ! $nodejs_version { + $nodejs_version = 'node_4.x' + } + } + } + group { $ethercalc_user: ensure => present, } @@ -60,33 +87,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 +147,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", diff --git a/templates/ethercalc.service.erb b/templates/ethercalc.service.erb new file mode 100644 index 0000000..05a9f88 --- /dev/null +++ b/templates/ethercalc.service.erb @@ -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