• SALT.STATES.CRON(states的crontab管理)


    salt.states.cron.present(name, user='root', minute='*', hour='*', daymonth='*', month='*', dayweek='*', comment=None, commented=False, identifier=False, special=None)
    以上的是cron模块present的使用方式,里面包含了支持的参数,具体的crontab系统定时任务使用方法可在linux系统里面使用man 5 crontab参阅。


    利用salt对crontab定时任务进行管理,这里就不对crontab的内容格式和用法进行解释。

    示例:

    1 date > /tmp/crontest:        
    2   cron.present:
    3     - user: root    #指定cron任务的用户
    4     - minute: 7
    5     - hour: 2

    执行之后在minion端生成的信息如下:
    # Lines below here are managed by Salt, do not edit #提示信息
    # SALT_CRON_IDENTIFIER:date > /tmp/crontest #crontab的名称标识符,每一个crontab都会有这样的一个标识符
    7 2 * * * date > /tmp/crontest #按照cron任务添加指定的格式,可使用identifier参数修改标识符内容

    各参数支持的一些形式:

    - minute: '*/5' #间隔方式
    - minute: random #随机方式
    - special: '@hourly' #指定特殊的执行方式,是一种比较简洁的方式,可以指定reboot后执行一次或每天执行一次

     1    string            meaning 
     2    ------           ------- 
     3    @reboot        Run once, at startup. 
     4    @yearly         Run once a year, "0 0 1 1 *". 
     5    @annually      (same as @yearly) 
     6    @monthly       Run once a month, "0 0 1 * *". 
     7    @weekly        Run once a week, "0 0 * * 0". 
     8    @daily           Run once a day, "0 0 * * *". 
     9    @midnight      (same as @daily) 
    10    @hourly         Run once an hour, "0 * * * *".

    salt.states.cron.file(name, source_hash='', source_hash_name=None, user='root', template=None, context=None, replace=True, defaults=None, backup='', **kwargs)
    cron模块file提供类似于file.managed的文件功能
    示例:

    1 foo_crontab:
    2   cron.file:
    3     - name: https://mydomain.tld/dir2/foo.txt
    4     - source_hash: https://mydomain.tld/hashes
    5     - source_hash_name: ./dir2/foo.txt

    使用参数说明:
      name:作为crontab源文件,源文件可以是托管在salt master上也存在于http或ftp网络空间中,如果是托管在master端的话,其书写形式为salt://spam/eggs,如果是网络地址需要提供source_hash参数进行校验。
      source_hash:里面包含指定网络文件的md5值和对应的文件名或路径。 

        例如:acbd18db4cc2f85cedef654fccc4a4d8 foo.txt,如果里面包含很多相似的路径则需要指定source_hash_name参数
        如下: 

    1         37b51d194a7513e45b56f6524f2d51f2    ./dir1/foo.txt
    2         acbd18db4cc2f85cedef654fccc4a4d8    ./dir2/foo.txt
    3         73feffa4b7f6bb68e44cf984c85f6e88    ./dir3/foo.txt

        这样的情况下可能导致hash值的匹配失败,所以尽量指定source_hash_name值。

      user:指定cron系统任务的用户
      template:支持文件里面的模板支持
      context:重写传递给模板的变量信息
      replace:是否设置为替换,如果设置为False的话,不进行覆盖操作
      defaults:定义模板变量值
      backup:是否启用备份模式


    salt.states.cron.absent(name, user='root', identifier=False, special=None, **kwargs)

    示例:

    1 crontest:
    2   cron.absent:
    3     - name: 'date > /tmp/crontest'    #指定是删除的cron任务ID
    4     - user: root

    salt.states.cron.env_absent(name, user='root')
    salt.states.cron.env_present(name, value=None, user='root')

  • 相关阅读:
    开始使用ACE工作
    I AM NOTHING vs I AM SOMETHING
    After you have run the GIS Server Post Install
    李开复的勇气论
    爱到底是什么?
    办公室交际不能碰触的“地雷”
    近日比较忙顾不上写随笔了
    什么是爱情?什么是婚姻?
    给自己科普一下SOA、AOP、ORM
    成功者需要具备的素质
  • 原文地址:https://www.cnblogs.com/solitarywares/p/7701286.html
Copyright © 2020-2023  润新知