Join my Laravel for REST API's course on Udemy 👀

Restart a service with SaltStack when a config file changes

May 23, 2021  ‐ 1 min read

In Linux many services require a restart when a config file is changed. Having to do this manually every time you change a configuration can be a pain. So doing this automatically would be great. With SaltStack you can achieve this by using watch in a state.

nginx:
  service.running:
    - reload: True
    - enable: true
    - watch:
        - file: nginx
  file.managed:
    - name: /etc/nginx/sites-enabled/website
    - source: salt://nginx/website

By "watching" a different state Salt makes sure to restart the service when the specified state has changed.