Tao
Tao

Reputation: 990

What does chef do in the end for action 'enable' for a service?

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?

Upvotes: 3

Views: 3015

Answers (2)

Nihit K
Nihit K

Reputation: 25

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

Upvotes: -1

Tao
Tao

Reputation: 990

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?

Upvotes: 1

Related Questions