首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SaltStack:必需的手表找不到

SaltStack:必需的手表找不到
EN

Server Fault用户
提问于 2015-06-25 06:25:10
回答 1查看 4K关注 0票数 1

我刚刚开始将SaltStack部署到我的服务器上。因此,我有以下文件/srv/salt/postfix/init.sls

代码语言:javascript
复制
# 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

基本上,每当/etc/postfix/canonical.db文件更改时,我希望重新启动后缀。

但是,每当运行此状态时,总是会收到postfix.restart状态的错误:

代码语言:javascript
复制
          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:

其他州运行得很完美。

我是新手。SaltStack,所以请帮我找出我哪里出了问题.如果我真的写了一个“适当的”SaltStack公式。

谢谢!

PS:salt --version返回salt 2015.5.0 (Lithium),我在Ubuntu上。

PPS:从*.db更改为canonical.db并不会改变结果:仍然存在watch:必需的错误。

PPPS:我最初将cmd.wait节放在/etc/postfix/canonical作业下,并将其划分为不同的作业,因为我认为错误是由于watch:找不到作业造成的。

更新:尾声

我放弃了原来的策略,转而使用基于GNU make的策略。

参考资料:http://www.unixwiz.net/techtips/postfix-makefiles.html

因此,init.sls现在看起来如下:

代码语言:javascript
复制
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

谢谢你试图回答我的问题!

EN

回答 1

Server Fault用户

发布于 2015-06-25 09:44:17

watch: file:必需不是指文件系统上的文件更改,而是指在文件系统执行过程中所定义的状态的更改。

在这种情况下,您必须观看state

代码语言:javascript
复制
- watch:
  - cmd: "/etc/postfix/canonical.db"

如果要对*.db文件的外部更改作出反应,则必须使用另一种方式。你可以看看反应堆系统:https://docs.saltstack.com/en/latest/topics/reactor/index.html。我不太了解它,但我认为它可以用于对文件系统的更改作出反应。

票数 4
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/701512

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档