3

When I declare a service as follows:

service "my_service" do
  action [:enable, :start]
end

What will chef actually execute in the end ? Will it just run service my_service enable and service my_service start?

For start, there should be no problem whether your linux server is using init.d or systemd, since the systemctl command is backward compatible with the service command. But there really isn't such option as enable for the service command. For example, if you run service my_service enable, you'll get

Usage: /sbin/service my_service {start|stop|reload|restart|try-restart|force-reload|status} 

In my case, I'm using systemd, and what I really what chef to do is to run systemctl enable my_service. But from the documentation I cannot tell what chef will do exactly in the end.

I could specify a custom start_command for the start action, but unfortunately there's no enable_command.

Does anyone have a clear answer or reference for that?

Tao
  • 970
  • 1
  • 12
  • 21

2 Answers2

1

ok, I just came across something called "provider" in chef. there's even an option for me to specify which provider to use for a service.

service my_service
  action [:enable, :start]
  provider Chef::Provider::Service::Systemd
end

So I think as long as I can make sure Chef::Provider::Service::Systemd is used, the enable action can be performed as expected.

But what is the default provider chef will use? and how to check and change that?

Tao
  • 970
  • 1
  • 12
  • 21
  • Default provider is depending on the Operating system and service type created using the Service resource. So there is no default provider. Here is the link to Chef provider source code, https://www.rubydoc.info/github/opscode/chef/Chef/Provider/Service It has the list of all supported service types. – Saravanan G Aug 10 '18 at 13:24
  • it seems we can safely rely on chef's default behavior. closing this question for now. – Tao Aug 30 '18 at 06:41
-1

Chef does the following for actions in the end : enable - Enable a service at boot. This action is equivalent to an Automatic startup type on the Microsoft Windows platform. This action is not supported when using System Resource Controller (SRC) on the AIX platform because System Resource Controller (SRC) does not have a standard mechanism for enabling and disabling services on system boot.

start - Start a service, and keep it running until stopped or disabled.

In your case -

it will enable the service at boot just like the automatic service enabler in windows

hope this will help

Nihit K
  • 25
  • 3
  • thanks for the reply. I've read those descriptions in https://docs.chef.io/resource_service.html, but I want to know what chef will actually do, i.e. how will chef "enable the service at boot" ? As long as it runs `systemctl enable my_service` then I'm fine. but how do I find out? – Tao Aug 10 '18 at 06:14