111111

salt-job管理

在SaltStack里执行任何一个操作都会在master上产生一个jid号,minion端会在cache目录下的proc目录创建一个以jid为名称的文件,这个文件里内容就是此次操作的记录,当操作完成后自动删除。

 

salt踢狗salt-run和moudle两种方式来管理JOB

1.通过salt-run来管理job

[root@node2 redis-4.0.10]# 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.list_job:'
        salt-run jobs.list_job 20130916125524463507
'jobs.list_jobs:'
    List all detectable jobs and associated functions
        salt-run jobs.list_jobs
'jobs.lookup_jid:'
        salt-run jobs.lookup_jid 20130916125524463507
        salt-run jobs.lookup_jid 20130916125524463507 outputter=highstate
'jobs.print_job:'
        salt-run jobs.print_job 20130916125524463507

 

2.可以看到此次的任务号。

[root@node2 redis-4.0.10]# salt 'node1' cmd.run 'sleep 100;whoami'
^CExiting on Ctrl-C
This job's jid is:
20181227213754124155
The minions may not have all finished running and any remaining minions will return upon completion. To look up the return data for this job later run:
salt-run jobs.lookup_jid 20181227213754124155

 

3.查看这个job的运行结果

[root@node2 redis-4.0.10]# salt-run jobs.lookup_jid 20181227213754124155
node1:
root

4.查看这个JOB的详细记录

[root@node2 redis-4.0.10]#  salt-run jobs.list_job 20181227213754124155
Arguments:
    - sleep 100;whoami
Function:
    cmd.run
Minions:
    - node1
Result:
    ----------
    node1:
        ----------
        return:
            root
StartTime:
    2018, Dec 27 21:37:54.124155
Target:
    node1
Target-type:
    glob
User:
    root
jid:
    20181227213754124155

 

二。通过saltstack module 来管理JOB

2.1 查看module的用法

[root@node2 redis-4.0.10]# salt \* sys.doc saltutil |grep job
'saltutil.find_cached_job:'
    Return the data for a specific cached job id
        salt '*' saltutil.find_cached_job <job id>
'saltutil.find_job:'
    Return the data for a specific job id
        salt '*' saltutil.find_job <job id>
'saltutil.kill_job:'
    Sends a kill signal (SIGKILL 9) to the named salt job's process
        salt '*' saltutil.kill_job <job id>
        salt '*' 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_job:'
    Sends a termination signal (SIGTERM 15) to the named salt job's process
        salt '*' saltutil.term_job <job id>

2.2. 接着用这个例子去测试

[root@node2 redis-4.0.10]# salt 'node1' cmd.run 'sleep 100;whoami'

[root@node2 redis-4.0.10]# salt 'node1' saltutil.find_job 20181227220403774993

可以直接kill这个job

[root@node2 redis-4.0.10]# salt 'node1' saltutil.kill_job 20181227220403774993
node1:
Signal 9 sent to job 20181227220656122140 at pid 143225

 

posted @ 2018-12-27 22:11  赵SIR  阅读(370)  评论(0编辑  收藏  举报