Search code examples
windows-servicessalt-project

How to set Recovery options in Windows services using SaltStack


I'm creating a custom Windows Service and deploying it on my salt-minions using Salt master. The code for it is as follows:

create_service_{{servicename}}:
  module.run:
    - name: service.create
    - m_name: {{servicename}}
    - bin_path: {{deploydir}}\path-to-service\{{servicename}}\{{servicename}}.exe
    - display_name: {{servicename}}
    - start_type: auto
    - onfail:
      - module: availibility_of_service_{{servicename}}

The service is getting created and deployed on all the minions as required however, I also want to set the recovery options via Salt as highlighted in the below screenshot. The below screenshot is just for reference and my actual service is a different one.

enter image description here

I tried finding salt commands to set this but couldn't. Can someone help me in this if I can set this to Restart via salt or its not available? If this isn't available via Salt then what is the other option?


Solution

  • You will need to use powershell for that. the issue is the the function salt uses to handle creating the service doesn't handle that functionality. in fact the only way to change that functionality in windows is with the sc command.

    see https://evotec.xyz/set-service-recovery-options-powershell/ for information on what to do to change those settings programmatically.