1

I'm just starting to deploy SaltStack to my servers. So, I have the following file /srv/salt/postfix/init.sls:

# Ensure postfix installed and set to autostart on boot
postfix:
  pkg.installed: []
  service.running:
    - require:
      - pkg: postfix
    - enable: True

# Restart on change to main.cf or any of the *.db files
postfix.restart:
  service.running:
    - require:
      - pkg: postfix
    - name: postfix
    - watch:
      - file: "/etc/postfix/main.cf"
      - file: "/etc/postfix/*.db"

# Without this, first watch above fails
/etc/postfix/main.cf:
  file.exists: []

/etc/postfix/canonical:
  file.managed:
    - require:
      - pkg: postfix
    - source: salt://postfix/canonical
    - template: jinja

/etc/postfix/canonical.db:
  cmd.wait:
    - name: /usr/sbin/postmap /etc/postfix/canonical
    - watch:
      - file: /etc/postfix/canonical

Basically, I want to restart Postfix whenever the /etc/postfix/canonical.db file changes.

But whenever I run this state, I always get an error for the postfix.restart state:

          ID: postfix.restart
    Function: service.running
        Name: postfix
      Result: False
     Comment: The following requisites were not found:
                                 watch:
                                     file: /etc/postfix/*.db
     Started:
    Duration:
     Changes:

Other states run perfectly.

I'm a beginner w.r.t. SaltStack, so please kindly assist me in finding out where did I go wrong... and if I actually have written a 'proper' SaltStack formula.

Thank you!


PS: salt --version returns salt 2015.5.0 (Lithium), and I'm on Ubuntu.

PPS: Changing from *.db to canonical.db does not change the result: Still error on that watch: requisite.

PPPS: I originally put the cmd.wait stanza under the /etc/postfix/canonical job, and separated it into a different job because I thought the error was due to watch: not finding the job.



UPDATE: EPILOGUE

I have given up the original strategy, and use a strategy based on GNU make instead.

Reference: http://www.unixwiz.net/techtips/postfix-makefiles.html

So the init.sls now looks like this:

postfix:
  pkg.installed: []
  service.running:
    - require:
      - pkg: postfix
    - enable: True

make:
  pkg.installed: []

/etc/postfix/Makefile:
  file.managed:
    - require:
      - pkg: postfix
      - pkg: make
    - source: salt://postfix/Makefile

refresh_db:
  cmd.run:
    - require:
      - pkg: postfix
      - pkg: make
    - name: make
    - cwd: /etc/postfix
    - order: last  ## IMPORTANT! This will force this particular job to run at the very last

/etc/postfix/canonical:
  file.managed:
    - require:
      - pkg: postfix
    - source: salt://postfix/canonical
    - template: jinja

Thank you for trying to answer my question!

| improve this question | | | | |
3

The watch: file: requisite doesn't refer to a file change on the filesystem, but to a change in your defined states during their execution.

In this case, you have to watch the state:

- watch:
  - cmd: "/etc/postfix/canonical.db"

If you want to react on an external change on the *.db files, you must use another way. You may have a look at the Reactor system: https://docs.saltstack.com/en/latest/topics/reactor/index.html. I don't know much about it but I think it can be used to react on filesystem changes.

| improve this answer | | | | |
  • Also didn't work if I use specific name. I've given up and modified the state completely. – pepoluan Jun 26 '15 at 5:50
  • Well, my bad, your state was not a file state but a cmd state. So your requisite should have been: ` - cmd: "/etc/postfix/canonical.db"` but it would execute every time, as the cmd state is always reporting changes, if it succeeds. – Christophe Drevet-Droguet Jun 26 '15 at 11:53
  • 1
    Ah, maybe you're right! But in any case, I've approached the problem differently now. Anyways, thanks for the insight! – pepoluan Jun 26 '15 at 20:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.