SaltStack: restart server (not only reload) on particular change
NickName:guettli Ask DateTime:2019-09-19T16:45:00

SaltStack: restart server (not only reload) on particular change

In most cases it is enough to reload our PostgreSQL server:

postgresql_service:
  service.running:
    - name: postgresql
    - enable: True
    - reload: True
    - watch:
      - file: postgresql.conf
      - file: pg_hba.conf
    - require:
      - pkg: postgresql
    - failhard: True

But on some particular changes a reload is not enough, a restart is needed.

For example if this line gets added to postgresql.conf, a restart is required:

shared_preload_libraries = 'pglogical'

How can I tell Salt to use restart if the above line gets added to the config file?

Example:

  1. salt runs and 'pglogical' was not in the config before and not after the salt run. The servers should get reloaded.
  2. The config changes and 'pglogical' gets added. Now the server should get restarted
  3. The config changes and 'pglogical' is already in the file. The server should get reloaded.

Copyright Notice:Content Author:「guettli」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/58007104/saltstack-restart-server-not-only-reload-on-particular-change

Answers
Siavash Sardari 2019-09-21T10:12:12

it depends on your sls architecture. for example if there is a variable in your pillar and you have a map.jinja you can handle this with something like bellow snippet.\n\n{% from \"postgresql/map.jinja\" import pillars with context %}\n\npostgresql_service:\n service.running:\n - name: postgresql\n - enable: True\n{% if pillars.shared_preload_libraries=='pglogical' %}\n - reload: True\n{% endif %}\n - watch:\n - file: postgresql.conf\n - file: pg_hba.conf\n - require:\n - pkg: postgresql\n - failhard: True\n",


More about “SaltStack: restart server (not only reload) on particular change” related questions

SaltStack: restart server (not only reload) on particular change

In most cases it is enough to reload our PostgreSQL server: postgresql_service: service.running: - name: postgresql - enable: True - reload: True - watch: - file: postgresq...

Show Detail

how to instruct saltstack to reload firewalld?

I'm trying to configure firewalld via saltstack state file (on Centos7). I can add services just fine to permanent configuration, but that indeed goes into 'permanent' configuration, not in the run...

Show Detail

Springboot- reload property values without server restart

I have a springboot application and an application.properties file from which the values get fetched when the application runs. I am finding a solution to change the property values and reload it w...

Show Detail

SaltStack watch file restart service won't work

I want SaltStack to reload or restart when the file 000-default-conf is changed, but when i manually edit the file on my debian9 system via ssh nothing happens. Can anyone help? The configuration ...

Show Detail

SaltStack watch file restart service won't work

I want SaltStack to reload or restart when the file 000-default-conf is changed, but when i manually edit the file on my debian9 system via ssh nothing happens. Can anyone help? The configuration ...

Show Detail

Saltstack not respecting watch/require

I am trying to deploy nginx using Saltstack. I am not using the nginx formula. Here is what I have: nginx: pkg.installed service.running: - require: - pkg: nginx - file: /etc...

Show Detail

Restart Nginx or reload certificate cache on cert change

Background: I am running an app inside Docker, that will be managed by random users that do often not have any knowledge about Docker itself. I am building the app to be as much configurable from ...

Show Detail

Saltstack action on state change

I have a following config for saltstack to apply a change on Windows machine: --- HKLM\SYSTEM\CurrentControlSet\Services\USBSTOR: reg.present: - name: - vname: "Start" - vtype: "REG_...

Show Detail

Installing SaltStack on RHEL 7?

I need help on installing saltstack on RHEL 7. RHEL 7 server is from AWS Amazon. $ cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.0 (Maipo) I'm getting an error during instal...

Show Detail

gunicorn: Is there a better way to reload gunicorn in described situation?

I have a django project with gunicorn and nginx. I'm deploying this project with saltstack In this project, I have a config.ini file that django views read. In case of nginx, I made that if ngin...

Show Detail