From 7cf08e1e39cb153e69e354444337c095a4464f6e Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Mon, 18 Dec 2017 15:02:26 +1100 Subject: [PATCH] Xenial: add a service file Add a service file for later Ubuntu versions. Centralise the logging into init.pp as it's not as easy to get logs to file from stdout/err via systemd. Fix up the logrotation while we're there Change-Id: I43ea764d070fb44502bda0c845485769dace6ff3 --- manifests/init.pp | 103 ++++++++++++++++++---------- manifests/site.pp | 2 + templates/etherpad-lite.service.erb | 16 +++++ 3 files changed, 85 insertions(+), 36 deletions(-) create mode 100644 templates/etherpad-lite.service.erb diff --git a/manifests/init.pp b/manifests/init.pp index b36c1c0..b535928 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -106,46 +106,77 @@ class etherpad_lite ( creates => "${base_install_dir}/etherpad-lite/node_modules", } - file { '/etc/init/etherpad-lite.conf': - ensure => present, - content => template('etherpad_lite/upstart.erb'), - replace => true, - owner => 'root', - } + case $::operatingsystem { + 'Ubuntu': { + if $::operatingsystemrelease <= '14.04' { - file { '/etc/init.d/etherpad-lite': - ensure => link, - target => '/lib/init/upstart-job', - } + file { '/etc/init/etherpad-lite.conf': + ensure => present, + content => template('etherpad_lite/upstart.erb'), + replace => true, + owner => 'root', + } - file { "${base_log_dir}/${ep_user}": - ensure => directory, - owner => $ep_user, - } + file { '/etc/init.d/etherpad-lite': + ensure => link, + target => '/lib/init/upstart-job', + } - include ::logrotate - logrotate::file { 'epliteerror': - log => "${base_log_dir}/${ep_user}/error.log", - options => [ - 'compress', - 'copytruncate', - 'missingok', - 'rotate 7', - 'daily', - 'notifempty', - ], - } + file { "${base_log_dir}/${ep_user}": + ensure => directory, + owner => $ep_user, + } - logrotate::file { 'epliteaccess': - log => "${base_log_dir}/${ep_user}/access.log", - options => [ - 'compress', - 'copytruncate', - 'missingok', - 'rotate 7', - 'daily', - 'notifempty', - ], + include ::logrotate + logrotate::file { 'epliteerror': + log => "${base_log_dir}/${ep_user}/error.log", + options => [ + 'compress', + 'copytruncate', + 'missingok', + 'rotate 7', + 'daily', + 'notifempty', + ], + } + + logrotate::file { 'epliteaccess': + log => "${base_log_dir}/${ep_user}/access.log", + options => [ + 'compress', + 'copytruncate', + 'missingok', + 'rotate 7', + 'daily', + 'notifempty', + ], + } + + } else { + + # Note logs go to syslog, can maybe change when + # https://github.com/systemd/systemd/pull/7198 is available + file { '/etc/systemd/system/etherpad-lite.service': + ensure => present, + content => template('etherpad_lite/etherpad-lite.service.erb'), + replace => true, + owner => 'root', + require => Exec['install_etherpad_dependencies'], + } + + # This is a hack to make sure that systemd is aware of the new service + # before we attempt to start it. + exec { 'etherpad-lite-systemd-daemon-reload': + command => '/bin/systemctl daemon-reload', + refreshonly => true, + require => File['/etc/systemd/system/etherpad-lite.service'], + } + + } + } + default: { + fail('This operating system not supported') + } } # end package management ugliness diff --git a/manifests/site.pp b/manifests/site.pp index 6acfd1f..f16b652 100644 --- a/manifests/site.pp +++ b/manifests/site.pp @@ -28,6 +28,7 @@ class etherpad_lite::site ( group => $etherpad_lite::ep_user, mode => '0600', require => Class['etherpad_lite'], + before => Service['etherpad-lite'], } file { "${base}/etherpad-lite/src/static/custom/pad.js": @@ -37,6 +38,7 @@ class etherpad_lite::site ( group => $etherpad_lite::ep_user, mode => '0644', require => Class['etherpad_lite'], + before => Service['etherpad-lite'], } } diff --git a/templates/etherpad-lite.service.erb b/templates/etherpad-lite.service.erb new file mode 100644 index 0000000..c346262 --- /dev/null +++ b/templates/etherpad-lite.service.erb @@ -0,0 +1,16 @@ +[Unit] +Description=Etherpad-lite, the collaborative editor. +After=syslog.target network.target + +[Service] +Type=simple +User=<%= @ep_user %> +Group=<%= @ep_user %> +WorkingDirectory=<%= @base_install_dir %>/etherpad-lite +ExecStart=/usr/bin/nodejs node_modules/ep_etherpad-lite/node/server.js +Restart=always +StandardOutput=syslog +StandardError=syslog + +[Install] +WantedBy=multi-user.target