Managing services
After packages and files, services are the entities to look out for in infrastructure management. For any system or application software, after the package is installed and the configuration files are modified, the next task is to make sure that the service is running and serves its purpose. In this recipe, you will learn how to manage services using Salt.
How to do it...
We will use the same minion and state directory as the previous recipe:
Create and edit the
/opt/salt-cookbook/staging/apache/service.sls
file to have the following entries:{% if grains['lsb_distrib_id'] == "CentOS" %} httpd: {% elif grains['lsb_distrib_id'] == "Ubuntu" %} apache2: {% endif %} pkg: - installed service: - running - enable: True - reload: True
Apply the state to the minion with the following command:
[root@salt-master ~]# salt 'salt-minion' state.sls apache.service saltenv=staging --state-output=terse salt-minion: Name: apache2 - Function: pkg.installed - Result: Changed...