zoukankan      html  css  js  c++  java
  • SaltStack中状态间关系unless、onlyif、require、require_in、watch、watch_in

    1、unless

      检查的命令,仅当unless选项指向的命令返回值为false时才执行name定义的命令

    cmd.run:
        {% if grains["osmajorrelease"]|string in ["5","6"] %}
        - name: 'nohup sh /alidata1/admin/esstats/tcp_stats.sh > /alidata1/admin/esstats/nohup.log 2>&1 &'
        {% else %}
        - name: 'systemd-run  --scope su - root -c "nohup sh /alidata1/admin/esstats/tcp_stats.sh > /alidata1/admin/esstats/nohup.log 2>&1 &"'
        {% endif %}
        - runas: root
        - unless: 'ps -ef |grep tcp_stats.sh|grep -v grep'
        - require:
          - file: tcp_stats_file
          - pkg: iftop_install
    View Code

    2、onlyif

     检查的命令,仅当unless选项指向的命令返回值为true时才执行name定义的命令

    set_link_logs:
      file.symlink:
        - name: /alidata1/admin/logs
        - target: /alidata1/admin/esstats/logs/season_8_cluster_tcp/
        - force: True
        - user: admin
        - group: admin
        - onlyif: test -d /alidata1/admin/esstats/logs/season_8_cluster_tcp/
    View Code

    3、require

    此状态依赖于另一个状态(我依赖某个状态,也就是某个状态失败了,我也就不执行name)

    4、require_in

    此状态另一个状态所依赖

    5、watch

    我的状态关注某一个状态

    6、watch_in

    我的状态被某一个状态所关注

    [root@linux-node1 apache]# vim init_require.sls 
    apache-install:
      pkg.installed:
        - name: httpd
    
    apache-config:
      file.managed:
        - name: /etc/httpd/conf/httpd.conf
        - source: salt://apache/files/httpd1.conf----->将此处的文件改错,模拟配置错误
        - user: root
        - group: root
        - mode: 644
    
    apache-service:
      service.running:
        - name: httpd
        - enable: True
        - require:---------------------------->使用require,表示依赖
          - pkg: apache-install--------------->依赖的状态模块为pkg模块,id为apache-install 也就是说这个安装成功后执行
          - file: apache-config--------------->依赖的状态模块为file模块,id为apache-config 也就是说文件管理成功后执行
    
    在执行service前 先pkg中的apache-install  然后在执行 fil中的 apache-config 模块执行都成功 才执行service.running模块
    
    #注意一个ID下面一个模块只能只用使用一次
    View Code
  • 相关阅读:
    Spring Boot 使用 Dom4j XStream 操作 Xml
    Spring Boot 使用 JAX-WS 调用 WebService 服务
    Spring Boot 使用 CXF 调用 WebService 服务
    Spring Boot 开发 WebService 服务
    Spring Boot 中使用 HttpClient 进行 POST GET PUT DELETE
    Spring Boot Ftp Client 客户端示例支持断点续传
    Spring Boot 发送邮件
    Spring Boot 定时任务 Quartz 使用教程
    Spring Boot 缓存应用 Memcached 入门教程
    ThreadLocal,Java中特殊的线程绑定机制
  • 原文地址:https://www.cnblogs.com/gavin11/p/11897663.html
Copyright © 2011-2022 走看看