ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

SaltSack 中Job管理

2019-09-26 15:53:02  阅读:263  来源: 互联网

标签:jobs saltutil 管理 list Job job run SaltSack salt


一、简介

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

    

标签:jobs,saltutil,管理,list,Job,job,run,SaltSack,salt
来源: https://www.cnblogs.com/gavin11/p/11592241.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有