I have a scenario where I need to take an action if another service is already running. Specifically, I want to install snmp monitoring if, for example, mysql is already running.
I know the "right" way to do this is to install mysql and its monitoring both based on pillar data, grain data, or some other top file filtering. However, in this scenario, mysql is being installed outside of configuration management (eg, an MSP has clients that install mysql but then rely on the hosting provider to configure monitoring).
What are the best practices in this situation?
Some solutions I've thought of:
- Create a custom grain that lists services that are running.
- Use the unless/only if (and a map file for different the OS distributions)
- A Beacon (stating that the service is running) and a reactor (to deploy)
- Calling the service.status execution module in jinja in the state file, such as:
{% set mysqlrunning = salt['service.status'](mysql_service) %}
{% if mysqlrunning %}
<rest of state file>
{% endif %}
While #4 seems simple enough, I am afraid it will be slow and use a lot of system resources in a large deployment (1000's of servers).
What are the best practices in this situation?