zoukankan      html  css  js  c++  java
  • SaltSack 中Job管理

    一、简介

    Jid: job id的格式为%Y%m%d%H%M%S%f

    master在下发指令消息时,会附带上产生的jid,minion在接收到指令开始执行时,会在本地的cachedir(默认是/var/cache/salt/minion)下的proc目录下产生该jid命名的文件,用于在执行过程中master查看当前任务执行的情况,在指令执行完毕蒋结果传送给master后,删除该临时文件。 master将minion的执行结果存放在本地/var/cache/salt/master/jobs目录中,默认缓存24小时(可以通过修改master配置文件中keepjobs选项调整)

    在执行指令时添加 -v 选项可以显示命令执行的job id 如: 

    [root@master reactor]# salt -v 'master' test.ping
    Executing job with jid 20190926032244634277   #可以显示任务的Job id
    -------------------------------------------
    
    master:
        True
    
    
    -------------------------------------------
    Summary
    -------------------------------------------
    # of minions targeted: 1
    # of minions returned: 1
    # of minions that did not return: 0
    # of minions with errors: 0
    -------------------------------------------
    [root@master reactor]#
    View Code

    二、Job基本管理

    saltutil模块中的job管理方法

    通过salt  *  sys.doc saltutil |grep job

    [root@master reactor]# salt master sys.doc saltutil | grep job
    saltutil.clear_job_cache:
        Forcibly removes job cache folders and files on a minion.
            salt '*' saltutil.clear_job_cache hours=12
    saltutil.find_cached_job:
        Return the data for a specific cached job id. Note this only works if
        cache_jobs has previously been set to True on the minion.
            salt '*' saltutil.find_cached_job <job id>
    saltutil.find_job:
        Return the data for a specific job id that is currently running.
            The job id to search for and return data.
            salt '*' saltutil.find_job <job id>
        Note that the find_job function only returns job information when the job is still running. If
        the job is currently running, the output looks something like this:
            # salt my-minion saltutil.find_job 20160503150049487736
        If the job has already completed, the job cannot be found and therefore the function returns
            # salt my-minion saltutil.find_job 20160503150049487736
    saltutil.kill_all_jobs:
        Sends a kill signal (SIGKILL 9) to all currently running jobs
            salt '*' saltutil.kill_all_jobs
    saltutil.kill_job:
        Sends a kill signal (SIGKILL 9) to the named salt job's process
            salt '*' saltutil.kill_job <job id>
            salt master_minion saltutil.runner jobs.list_jobs
    saltutil.signal_job:
        Sends a signal to the named salt job's process
            salt '*' saltutil.signal_job <job id> 15
    saltutil.term_all_jobs:
        Sends a termination signal (SIGTERM 15) to all currently running jobs
            salt '*' saltutil.term_all_jobs
    saltutil.term_job:
        Sends a termination signal (SIGTERM 15) to the named salt job's process
            salt '*' saltutil.term_job <job id>
    View Code

    1、salt '*' saltutil.running            #查看minion当前正在运行的jobs

    2、salt '*' saltutil.find_job <jid>            #查看指定jid的job(minion正在运行的jobs)

    3、salt '*' saltutil.signal_job <jid> <single>    #给指定的jid进程发送信号

    4、salt '*' saltutil.term_job <jid>        #终止指定的jid进程(信号为15)

    5、salt '*' saltutil.kill_job <jid>          #终止指定的jid进程(信号为9)

     

    salt runner中的job管理方法

    可以执行salt-run -d |grep jobs  查看到相关jobs命令

    [root@master reactor]# salt-run  -d | grep jobs
    jobs.active:
        Return a report on all actively running jobs from a job id centric
            salt-run jobs.active
    jobs.exit_success:
            salt-run jobs.exit_success 20160520145827701627
    jobs.last_run:
        List all detectable jobs and associated functions
            salt-run jobs.last_run
            salt-run jobs.last_run target=nodename
            salt-run jobs.last_run function='cmd.run'
            salt-run jobs.last_run metadata="{'foo': 'bar'}"
    jobs.list_job:
            salt-run jobs.list_job 20130916125524463507
            salt-run jobs.list_job 20130916125524463507 --out=pprint
    jobs.list_jobs:
        List all detectable jobs and associated functions
            If more than one of the below options are used, only jobs which match
                salt-run jobs.list_jobs search_metadata='{"foo": "bar", "baz": "qux"}'
            Can be passed as a string or a list. Returns jobs which match the
                salt-run jobs.list_jobs search_function='test.*'
                salt-run jobs.list_jobs search_function='["test.*", "pkg.install"]'
                    salt-run jobs.list_jobs search_function='test.*,pkg.install'
            Can be passed as a string or a list. Returns jobs which match the
                salt-run jobs.list_jobs search_target='*.mydomain.tld'
                salt-run jobs.list_jobs search_target='["db*", "myminion"]'
                    salt-run jobs.list_jobs search_target='db*,myminion'
            module is not installed, this argument will be ignored). Returns jobs
            module is not installed, this argument will be ignored). Returns jobs
            salt-run jobs.list_jobs
            salt-run jobs.list_jobs search_function='test.*' search_target='localhost' search_metadata='{"bar": "foo"}'
            salt-run jobs.list_jobs start_time='2015, Mar 16 19:00' end_time='2015, Mar 18 22:00'
    jobs.list_jobs_filter:
        List all detectable jobs and associated functions
            salt-run jobs.list_jobs_filter 50
            salt-run jobs.list_jobs_filter 100 filter_find_job=False
    jobs.lookup_jid:
            salt-run jobs.lookup_jid 20130916125524463507
            salt-run jobs.lookup_jid 20130916125524463507 --out=highstate
    jobs.print_job:
            salt-run jobs.print_job 20130916125524463507
        It can also be used to schedule jobs directly on the master, for example:
    [root@master reactor]# 
    View Code

    1、salt-run jobs.active                 #查看所有minion当前正在运行的jobs(在所有minions上运行saltutil.running)

    2、salt-run jobs.lookup_jid <jid>         #从master jobs cache中查询指定jid的运行结果

    3、salt-run jobs.list_jobs                #列出当前master jobs cache中所有job

        

  • 相关阅读:
    centos 修改语言、时区
    去除 ufeff
    Docker介绍及使用
    消息队列
    数据结构与算法
    Haystack
    Python面向对象之魔术方法
    关于Redis处理高并发
    Redis
    RESTful规范
  • 原文地址:https://www.cnblogs.com/gavin11/p/11592241.html
Copyright © 2011-2022 走看看