Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reload a systemd service when using Chef

I have a systemd service that is managed using Chef.

What is the Chef way to do a systemctl daemon-reload?

So for example as shown below, I can perform a reload of my myservice but this doensn't do a systemctl daemon-reload.

template '/etc/systemd/system/myservice.service do
  notifies :reload,'service[myservice]', :immediately 
end

service 'myservice' do
  supports status: true ...
  action %i[start enable]
end
like image 707
onknows Avatar asked Oct 16 '25 20:10

onknows


1 Answers

We can manage Systemd service definitions using the systemd_unit resource. This way, if the service configuration changes it will trigger a reload with the triggers_reload (set to true by default) property.

Since you are using a template, you could use the systemd_unit resource with reload action for your service.

template '/etc/systemd/system/myservice.service' do
  notifies :reload, 'systemd_unit[myservice.service]', :immediately 
end

systemd_unit 'myservice.service' do
  action :nothing
end

Other option is to create an execute resource, and run the actual daemon-reload command:

template '/etc/systemd/system/myservice.service' do
  notifies :run, 'execute[daemon-reload]', :immediately 
end

execute 'daemon-reload' do
  command 'systemctl daemon-reload'
  action :nothing
end
like image 107
seshadri_c Avatar answered Oct 19 '25 14:10

seshadri_c