Browse Source

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
Jens Harbott 1 year ago
parent
commit
05b1414b9b
3 changed files with 127 additions and 58 deletions
  1. 111
    57
      manifests/init.pp
  2. 1
    1
      metadata.json
  3. 15
    0
      templates/ethercalc.service.erb

+ 111
- 57
manifests/init.pp View File

@@ -15,12 +15,41 @@ class ethercalc (
15 15
   $base_log_dir     = '/var/log',
16 16
   $ethercalc_user   = 'ethercalc',
17 17
   $ethercalc_version= '0.20161220.1',
18
-  # If set to system will install system package.
19
-  $nodejs_version   = 'node_4.x',
18
+  # If set to system will install system package, otherwise
19
+  # we try to choose one based on the host platform
20
+  $nodejs_version   = undef,
20 21
 ) {
21 22
 
22 23
   $path = '/usr/local/bin:/usr/bin:/bin'
23 24
 
25
+  # For trusty default to upstart, node 4.x.  For Xenial onwards use
26
+  # node 6.x for updated dependencies and the default systemd service
27
+  # file
28
+  case $::operatingsystem {
29
+    'Ubuntu': {
30
+      if $::operatingsystemrelease <= '14.04' {
31
+        $use_upstart = true
32
+        if ! $nodejs_version {
33
+          $use_nodejs_version = '4.x'
34
+        }
35
+      }
36
+      else {
37
+        if ! $nodejs_version {
38
+          $use_nodejs_version = '6.x'
39
+        }
40
+      }
41
+    }
42
+    default: {
43
+      # TODO(ianw) -- not sure this is a sane default, but it's the
44
+      # way it was...
45
+      if ! $nodejs_version {
46
+        $use_nodejs_version = '4.x'
47
+      } else {
48
+        $use_nodejs_version = $nodejs_version
49
+      }
50
+    }
51
+  }
52
+
24 53
   group { $ethercalc_user:
25 54
     ensure => present,
26 55
   }
@@ -46,11 +75,16 @@ class ethercalc (
46 75
     }
47 76
   }
48 77
 
78
+  file { "${base_log_dir}/${ethercalc_user}":
79
+    ensure => directory,
80
+    owner  => $ethercalc_user,
81
+  }
82
+
49 83
   anchor { 'nodejs-package-install': }
50 84
 
51
-  if ($nodejs_version != 'system') {
85
+  if ($use_nodejs_version != 'system') {
52 86
     class { '::nodejs':
53
-      repo_url_suffix => $nodejs_version,
87
+      repo_url_suffix => $use_nodejs_version,
54 88
       before          => Anchor['nodejs-package-install'],
55 89
     }
56 90
   } else {
@@ -60,70 +94,90 @@ class ethercalc (
60 94
     }
61 95
   }
62 96
 
63
-  file { '/usr/local/bin/node':
64
-    ensure  => link,
65
-    target  => '/usr/bin/nodejs',
66
-    require => Anchor['nodejs-package-install'],
67
-    before  => Anchor['nodejs-anchor'],
68
-  }
69
-
70
-  anchor { 'nodejs-anchor': }
71
-
72 97
   exec { 'install-ethercalc':
73 98
     command => "npm install ethercalc@${ethercalc_version}",
74 99
     unless  => "npm ls | grep ethercalc@${ethercalc_version}",
75 100
     path    => $path,
76 101
     cwd     => $base_install_dir,
77
-    require => Anchor['nodejs-anchor'],
102
+    require => Anchor['nodejs-package-install'],
78 103
   }
79 104
 
80
-  file { '/etc/init/ethercalc.conf':
81
-    ensure  => present,
82
-    content => template('ethercalc/upstart.erb'),
83
-    replace => true,
84
-    owner   => 'root',
85
-  }
105
+  # TODO(ianw): remove this when trusty is dropped
106
+  if $use_upstart {
86 107
 
87
-  file { '/etc/init.d/ethercalc':
88
-    ensure => link,
89
-    target => '/lib/init/upstart-job',
90
-  }
108
+    file { '/etc/init/ethercalc.conf':
109
+      ensure  => present,
110
+      content => template('ethercalc/upstart.erb'),
111
+      replace => true,
112
+      owner   => 'root',
113
+      require => Exec['install-ethercalc'],
114
+    }
91 115
 
92
-  file { "${base_log_dir}/${ethercalc_user}":
93
-    ensure => directory,
94
-    owner  => $ethercalc_user,
95
-  }
116
+    file { '/etc/init.d/ethercalc':
117
+      ensure => link,
118
+      target => '/lib/init/upstart-job'
119
+    }
96 120
 
97
-  service { 'ethercalc':
98
-    ensure  => running,
99
-    enable  => true,
100
-    require => File['/etc/init/ethercalc.conf'],
101
-  }
121
+    service { 'ethercalc':
122
+      ensure  => running,
123
+      enable  => true,
124
+      require => File['/etc/init/ethercalc.conf'],
125
+    }
102 126
 
103
-  include ::logrotate
104
-  logrotate::file { 'ethercalc_error':
105
-    log     => "${base_log_dir}/${ethercalc_user}/error.log",
106
-    options => [
107
-      'compress',
108
-      'copytruncate',
109
-      'missingok',
110
-      'rotate 7',
111
-      'daily',
112
-      'notifempty',
113
-    ],
114
-    require => Service['ethercalc'],
115
-  }
127
+    include ::logrotate
128
+    logrotate::file { 'ethercalc_error':
129
+      log     => "${base_log_dir}/${ethercalc_user}/error.log",
130
+      options => [
131
+                  'compress',
132
+                  'copytruncate',
133
+                  'missingok',
134
+                  'rotate 7',
135
+                  'daily',
136
+                  'notifempty',
137
+                  ],
138
+      require => Service['ethercalc'],
139
+    }
140
+
141
+    logrotate::file { 'ethercalc_access':
142
+      log     => "${base_log_dir}/${ethercalc_user}/access.log",
143
+      options => [
144
+                  'compress',
145
+                  'copytruncate',
146
+                  'missingok',
147
+                  'rotate 7',
148
+                  'daily',
149
+                  'notifempty',
150
+                  ],
151
+      require => Service['ethercalc'],
152
+    }
116 153
 
117
-  logrotate::file { 'ethercalc_access':
118
-    log     => "${base_log_dir}/${ethercalc_user}/access.log",
119
-    options => [
120
-      'compress',
121
-      'copytruncate',
122
-      'missingok',
123
-      'rotate 7',
124
-      'daily',
125
-      'notifempty',
126
-    ],
127
-    require => Service['ethercalc'],
154
+  } else {
155
+
156
+    # Note logs go to syslog, can maybe change when
157
+    # https://github.com/systemd/systemd/pull/7198 is available
158
+    file { '/etc/systemd/system/ethercalc.service':
159
+      ensure  => present,
160
+      content => template('ethercalc/ethercalc.service.erb'),
161
+      replace => true,
162
+      owner   => 'root',
163
+      require => Exec['install-ethercalc'],
164
+    }
165
+
166
+    # This is a hack to make sure that systemd is aware of the new service
167
+    # before we attempt to start it.
168
+    exec { 'ethercalc-systemd-daemon-reload':
169
+      command     => '/bin/systemctl daemon-reload',
170
+      before      => Service['ethercalc'],
171
+      subscribe   => File['/etc/systemd/system/ethercalc.service'],
172
+      refreshonly => true,
173
+    }
174
+
175
+    service { 'ethercalc':
176
+      ensure  => running,
177
+      enable  => true,
178
+      require => File['/etc/systemd/system/ethercalc.service'],
179
+    }
128 180
   }
181
+
182
+
129 183
 }

+ 1
- 1
metadata.json View File

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

+ 15
- 0
templates/ethercalc.service.erb View File

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

Loading…
Cancel
Save