Hello, Chefs. I’m writing a cookbook to manage a certain security agent on Linux – to deploy the RPM, and enable and start the service. But I am having problems, and this is the first package/service I have worked with that does not seem to play well with Chef. Chef thinks the service is running when it’s not, and thinks it’s not running when it is.
I think the problem is that for this package, the RHEL7 command “service SERVICE_NAME status” returns 1 if the service is running, and 0 if the service is not running. I am under the impression that the Chef “service” resource will run that status command to check the status of the service so it doesn’t start or stop it unnecessarily. Is that true? If so, that would explain the Chef behavior I’m seeing.
Has any of you come across a service on Linux for which “service SERVICE_NAME status” returns 1 if the service is running, and 0 if the service is not running? Why might the vendor have built it (their init.d script for this package) that way?
I’ve seen very uncooperative “service NAME status” commands. Have you tried writing your own status command for this service, call the original command and swap the returns. The service resource lets you specify the status command to be used for a service.
Thanks very much for the tip. @markgibbons! I worked around the anomaly before I saw your note by writing a simple custom resource for this service. I appreciate your tip about how Chef’s “service” resource takes an optional “status_command” property where you can specify the command to check the run status for a service. I didn’t know that, and that would be much cleaner, so I think I’ll switch to that. (I’ll then be able to get rid of the custom resource file I created, and the custom ChefSpec matcher I created to get my unit tests for the cookbook to work.)
You also answered my question by saying you’ve seen this type of behavior with other services. For some reason I thought it was a “basic truth” that in Linux the “service NAME status” command returned zero if the service was running, but it sounds like that’s not always the case.
I appreciate your help!