Skip to content

Commit c40e8a7

Browse files
Merge pull request #302 from yakara-ltd/systemd
Various systemd-related improvements
2 parents e754001 + 7c3ab53 commit c40e8a7

File tree

6 files changed

+98
-108
lines changed

6 files changed

+98
-108
lines changed

README.md

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -415,24 +415,6 @@ You may also pass an array of masters to monitor like so:
415415

416416
## Resources/Providers
417417

418-
### `service`
419-
420-
Actions:
421-
422-
* `start`
423-
* `stop`
424-
* `restart`
425-
* `enable`
426-
* `disable`
427-
428-
Simply provide redis<server_name> where server name is the port if you haven't given it a name.
429-
430-
```ruby
431-
service "redis<server_name>" do
432-
action [:start,:stop,:restart,:enable,:disable]
433-
end
434-
```
435-
436418
### `install`
437419

438420
Actions:

attributes/default.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@
6767
default['redisio']['install_dir'] = nil
6868

6969
# Job control related options (initd, upstart, or systemd)
70-
if node['platform_family'] == 'rhel' && Gem::Version.new(node['platform_version']) > Gem::Version.new('7.0.0')
71-
default['redisio']['job_control'] = 'systemd'
72-
elsif node['platform_family'] == 'freebsd'
73-
default['redisio']['job_control'] = 'rcinit'
74-
else
75-
default['redisio']['job_control'] = 'initd'
76-
end
70+
default['redisio']['job_control'] = if node['init_package'] == 'systemd'
71+
'systemd'
72+
elsif node['platform_family'] == 'freebsd'
73+
'rcinit'
74+
else
75+
'initd'
76+
end
7777

7878
# Init.d script related options
7979
default['redisio']['init.d']['required_start'] = []

providers/configure.rb

Lines changed: 87 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -296,61 +296,93 @@ def configure
296296
node['redisio']['bin_path']
297297
end
298298

299-
template "/etc/init.d/redis#{server_name}" do
300-
source 'redis.init.erb'
301-
cookbook 'redisio'
302-
owner 'root'
303-
group 'root'
304-
mode '0755'
305-
variables(
306-
name: server_name,
307-
bin_path: bin_path,
308-
port: current['port'],
309-
address: current['address'],
310-
user: current['user'],
311-
configdir: current['configdir'],
312-
piddir: piddir,
313-
requirepass: current['requirepass'],
314-
shutdown_save: current['shutdown_save'],
315-
platform: node['platform'],
316-
unixsocket: current['unixsocket'],
317-
ulimit: descriptors,
318-
required_start: node['redisio']['init.d']['required_start'].join(' '),
319-
required_stop: node['redisio']['init.d']['required_stop'].join(' ')
320-
)
321-
only_if { node['redisio']['job_control'] == 'initd' }
322-
end
323-
template "/etc/init/redis#{server_name}.conf" do
324-
source 'redis.upstart.conf.erb'
325-
cookbook 'redisio'
326-
owner current['user']
327-
group current['group']
328-
mode '0644'
329-
variables(
330-
name: server_name,
331-
bin_path: bin_path,
332-
port: current['port'],
333-
user: current['user'],
334-
group: current['group'],
335-
configdir: current['configdir'],
336-
piddir: piddir
337-
)
338-
only_if { node['redisio']['job_control'] == 'upstart' }
339-
end
340-
template "/usr/local/etc/rc.d/redis#{server_name}" do
341-
source 'redis.rcinit.erb'
342-
cookbook 'redisio'
343-
owner current['user']
344-
group current['group']
345-
mode '0755'
346-
variables(
347-
name: server_name,
348-
bin_path: bin_path,
349-
user: current['user'],
350-
configdir: current['configdir'],
351-
piddir: piddir
352-
)
353-
only_if { node['redisio']['job_control'] == 'rcinit' }
299+
case node['redisio']['job_control']
300+
when 'initd'
301+
template "/etc/init.d/redis#{server_name}" do
302+
source 'redis.init.erb'
303+
cookbook 'redisio'
304+
owner 'root'
305+
group 'root'
306+
mode '0755'
307+
variables(
308+
name: server_name,
309+
bin_path: bin_path,
310+
port: current['port'],
311+
address: current['address'],
312+
user: current['user'],
313+
configdir: current['configdir'],
314+
piddir: piddir,
315+
requirepass: current['requirepass'],
316+
shutdown_save: current['shutdown_save'],
317+
platform: node['platform'],
318+
unixsocket: current['unixsocket'],
319+
ulimit: descriptors,
320+
required_start: node['redisio']['init.d']['required_start'].join(' '),
321+
required_stop: node['redisio']['init.d']['required_stop'].join(' ')
322+
)
323+
end
324+
when 'upstart'
325+
template "/etc/init/redis#{server_name}.conf" do
326+
source 'redis.upstart.conf.erb'
327+
cookbook 'redisio'
328+
owner current['user']
329+
group current['group']
330+
mode '0644'
331+
variables(
332+
name: server_name,
333+
bin_path: bin_path,
334+
port: current['port'],
335+
user: current['user'],
336+
group: current['group'],
337+
configdir: current['configdir'],
338+
piddir: piddir
339+
)
340+
end
341+
when 'rcinit'
342+
template "/usr/local/etc/rc.d/redis#{server_name}" do
343+
source 'redis.rcinit.erb'
344+
cookbook 'redisio'
345+
owner current['user']
346+
group current['group']
347+
mode '0755'
348+
variables(
349+
name: server_name,
350+
bin_path: bin_path,
351+
user: current['user'],
352+
configdir: current['configdir'],
353+
piddir: piddir
354+
)
355+
end
356+
when 'systemd'
357+
service_name = "redis@#{server_name}"
358+
reload_name = "#{service_name} systemd reload"
359+
360+
file "/etc/tmpfiles.d/#{service_name}.conf" do
361+
content "d #{piddir} 0755 #{current['user']} #{current['group']}\n"
362+
owner 'root'
363+
group 'root'
364+
mode '0644'
365+
end
366+
367+
execute reload_name do
368+
command 'systemctl daemon-reload'
369+
action :nothing
370+
end
371+
372+
template "/lib/systemd/system/#{service_name}.service" do
373+
source 'redis@.service.erb'
374+
cookbook 'redisio'
375+
owner 'root'
376+
group 'root'
377+
mode '0644'
378+
variables(
379+
bin_path: bin_path,
380+
user: current['user'],
381+
group: current['group'],
382+
limit_nofile: current['maxclients'] + 32
383+
)
384+
notifies :run, "execute[#{reload_name}]", :immediately
385+
end
354386
end
355387
end
356388
end # servers each loop

recipes/configure.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,6 @@
3838
base_piddir redis['base_piddir']
3939
end
4040

41-
template '/usr/lib/systemd/system/redis@.service' do
42-
source 'redis@.service.erb'
43-
variables(
44-
bin_path: node['redisio']['bin_path'],
45-
limit_nofile: redis['default_settings']['maxclients'] + 32
46-
)
47-
only_if { node['redisio']['job_control'] == 'systemd' }
48-
end
49-
5041
# Create a service resource for each redis instance, named for the port it runs on.
5142
redis_instances.each do |current_server|
5243
server_name = current_server['name'] || current_server['port']

recipes/enable.rb

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@
2020

2121
redis = node['redisio']
2222

23-
execute 'reload-systemd-enable' do
24-
command '/usr/bin/systemctl daemon-reload'
25-
only_if { node['redisio']['job_control'] == 'systemd' }
26-
action :nothing
27-
end
28-
2923
redis['servers'].each do |current_server|
3024
server_name = current_server['name'] || current_server['port']
3125
resource_name = if node['redisio']['job_control'] == 'systemd'
@@ -35,13 +29,5 @@
3529
end
3630
resource = resources(resource_name)
3731
resource.action Array(resource.action)
38-
resource.action << :start
39-
if node['redisio']['job_control'] != 'systemd'
40-
resource.action << :enable
41-
else
42-
link "/etc/systemd/system/multi-user.target.wants/redis@#{server_name}.service" do
43-
to '/usr/lib/systemd/system/redis@.service'
44-
notifies :run, 'execute[reload-systemd-enable]', :immediately
45-
end
46-
end
32+
resource.action.concat [:start, :enable]
4733
end

templates/default/redis@.service.erb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
[Unit]
2-
Description=Redis persistent key-value database
2+
Description=Redis (%i) persistent key-value database
33
After=network.target
44

55
[Service]
66
ExecStart=<%= @bin_path %>/redis-server /etc/redis/%i.conf --daemonize no
7-
ExecStop=/usr/bin/redis-shutdown
8-
User=redis
9-
Group=redis
7+
User=<%= @user %>
8+
Group=<%= @group %>
109
LimitNOFILE=<%= @limit_nofile %>
1110

1211
[Install]

0 commit comments

Comments
 (0)