Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing /usr/bin/redis-shutdown script #271

Closed
maoueh opened this issue May 25, 2016 · 3 comments · Fixed by #302
Closed

Missing /usr/bin/redis-shutdown script #271

maoueh opened this issue May 25, 2016 · 3 comments · Fixed by #302

Comments

@maoueh
Copy link

maoueh commented May 25, 2016

Hi,

I'm installing redis using cookbok version 2.4.2 on CentOS 7 using a wrapper cookbook (mainly to enforce version installed and default server settings).

I noticed the systemd script has its ExecStop command set to /usr/bin/redis-shutdown. However. when installing, this command does not exist. Is this file supposed to be present when installing by default?

This does not create apparent problem has systemd is smart enough to kill the process. However, for guaranteed persistence, the redis daemon must be gracefully stopped. Also, even if the start command is templated with %i, the shutdown command seems not so I wonder what it was supposed to do.

ping @benLogN

@maoueh
Copy link
Author

maoueh commented Jun 10, 2016

Here the current "fixup" recipe I'm currently using in my wrapper script. However, even if it's working, I think a single generic unit file for systemd is not correct because user and group can be different by server. As such, I did not find a way yet to make it generic based on the server name. To fully support all uses cases, I guess one unit for each service would be a better option.

Also, I did found some problems on CentOS with the current unit. The redis run_dir is in a tmpfs filesystem. On reboot, the folder is cleared up. On the next reboot, the /var/run/redis folder is not re-created by the unit preventing the service from starting. My fixup recipe fix this also.

# _finalize_systemd.rb
template "#{node['redisio']['bin_path']}/redis-shutdown" do
  source 'redis-shutdown.erb'
  user 'redis'
  group 'redis'
  mode '0755'
  variables(
    bin_dir: node['redisio']['bin_path'],
    redis_servers: node['redisio']['servers']
  )
end

template "/usr/lib/systemd/system/[email protected]" do
  source 'systemd/[email protected]'
  user 'root'
  group 'root'
  mode '0644'
  variables(
    user: node['redisio']['default_settings']['user'],
    group: node['redisio']['default_settings']['group'],
    bin_dir: node['redisio']['bin_path'],
    run_dir: node['redisio']['base_piddir']
  )

  notifies :run, 'bash[reload systemd units]', :immediately

  node['redisio']['servers'].each do |redis_server|
    notifies :restart, "service[redis@#{redis_server['name']}]", :delayed
  end
end

bash 'reload systemd units' do
  code 'systemctl daemon-reload'

  action :nothing
end
# templates/default/redis-shutdown.erb
#!/usr/bin/env sh

##
# Generated by Chef
#
# Script that shut down a named redis instance
#

case $1 in
<% @redis_servers.each do |redis_server| %>
"<%= redis_server['name'] %>")
  exec <%= @bin_dir %>/redis-cli -h 127.0.0.1 -p <%= redis_server['port'] %> shutdown
  ;;
<% end %>
*)
  echo "No instance named '${1}' is known to this script."
  exit 1
  ;;
esac

echo "Should never reached here, something gone wrong!"
exit 2
# templates/default/systemd/[email protected]
[Unit]
Description=Redis (%i) persistent key-value database
After=network.target

[Service]
PermissionsStartOnly=true
ExecStartPre=/bin/mkdir -p <%= @run_dir %>/%i
ExecStartPre=/bin/chown <%= @user %>:<%= @group %> <%= @run_dir %>/%i
ExecStart=<%= @bin_dir %>/redis-server /etc/redis/%i.conf --daemonize no
ExecStop=<%= @bin_dir %>/redis-shutdown %i
ExecStopPost=/bin/rm -rf <%= @run_dir %>/%i
User=<%= @user %>
Group=<%= @group %>

[Install]
WantedBy=multi-user.target

@chewi
Copy link
Contributor

chewi commented Nov 16, 2016

The redis-shutdown part is dealt with in #302. I haven't looked at the /var/run/redis issue yet but this should be fixed with tmpfiles.d instead.

Actually if you're installing from a distro package then /usr/lib/tmpfiles.d/redis.conf will already deal with this. An identical file should therefore be put in place by the install LWRP.

@lock
Copy link

lock bot commented Nov 28, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants