Creating custom services


#1

Hi!

Say I have a Unix wrapper that is used to start/stop/etc the apache web server. The name of the wrapper is runapache and runs off of a /software/bin/ directory. I accepts typical start/stop/restart directives, but also some custom ones to recreate http.conf files and such. Why you need this runapache wrapper you ask? Well, it’s a long story, but I have to live with that company decision I didn’t make and make it work :wink:

Based on http://docs.opscode.com/resource_service.html I thought I could create a custom service with something like:

service “runapache” do
supports :restart => true, :stop => true
init_command "/software/bin/runapache"
restart_command "runapache kill"
end

However, when I try to make use of this service I get an error saying runapache does not exist in /etc/init.d/ I understood init_command should be used to determine an alternate location. What am I missing? I am using Chef Version: 10.18.2

Thanks,

Luis


#2

Setting init_command should be replacing the call to a script in /etc/init.d according to https://github.com/opscode/chef/blob/master/lib/chef/provider/service.rb#L158-164 but the init provider looks to override it https://github.com/opscode/chef/blob/master/lib/chef/provider/service/init.rb#L32 with the default; /etc/init.d/runapache in your case. I’ve never used the custom commands but you could try adding individual commands (start_command, stop_command) to the service resource definition.

On Monday, April 28, 2014 at 6:48 PM, Luis Cosmes wrote:

Hi!

Say I have a Unix wrapper that is used to start/stop/etc the apache web server. The name of the wrapper is runapache and runs off of a /software/bin/ directory. I accepts typical start/stop/restart directives, but also some custom ones to recreate http.conf files and such. Why you need this runapache wrapper you ask? Well, it’s a long story, but I have to live with that company decision I didn’t make and make it work :wink:

Based on http://docs.opscode.com/resource_service.html I thought I could create a custom service with something like:

service “runapache” do
supports :restart => true, :stop => true
init_command "/software/bin/runapache"
restart_command "runapache kill"
end

However, when I try to make use of this service I get an error saying runapache does not exist in /etc/init.d/ I understood init_command should be used to determine an alternate location. What am I missing? I am using Chef Version: 10.18.2

Thanks,

Luis