Saltstack Study Notes 9-job

Source: Internet
Author: User
Tags glob saltstack

Any action in Saltstack will generate a Jid number on master, as shown in the previous section of data stored on Redis


./REDIS-CLI Monitor

Ok

1461054358.412376 [0 127.0.0.1:58564] "select" "0"

1461054358.412717 [0 127.0.0.1:58564] "SET" "minion1:20160419162558137768" "{\" fun_args\ ": [\" hostname\ "], \" jid\ ": \" 20160419162558137768\ ", \" return\ ": \" minion1\ ", \" Retcode\ ": 0, \" success\ ": true, \" fun\ ": \" cmd.run\ ", \" id\ ": \" Minion1\ "}"

1461054358.413143 [0 127.0.0.1:58564] "lpush" "Minion1:cmd.run" "20160419162558137768"

1461054358.413482 [0 127.0.0.1:58564] "sadd" "Minions" "Minion1"

1461054358.413791 [0 127.0.0.1:58564] "sadd" "Jids" "20160419162558137768"

1461058032.241332 [0 127.0.0.1:58567] "select" "0"

1461058032.241541 [0 127.0.0.1:58567] "SET" "minion1:20160419172712073319" "{\" fun_args\ ": [\" free-m\ "], \" jid\ ": \"           20160419172712073319\ ", \" return\ ": \" Total used free shared buffers Cached\\nmem:         988 826 162 0 545\\n-/+ buffers/cache:239 749\\nswap: 4095 0 4095\ ", \" Retcode\ ": 0, \" success\ ": true, \" fun\ ": \" cmd.run\ ", \" id\ ": \" minion1\ "}"

1461058032.242293 [0 127.0.0.1:58567] "lpush" "Minion1:cmd.run" "20160419172712073319"

1461058032.242815 [0 127.0.0.1:58567] "sadd" "Minions" "Minion1"

1461058032.243637 [0 127.0.0.1:58567] "sadd" "Jids" "20160419172712073319"


The Minion end will create a file with Jid name in the proc directory under the cache directory, which is the record of this operation, and the file will be deleted automatically when the operation is completed. The master side records the details of each operation, and this record is available under jobs under the master cache directory. The following is an example of how daily job management is done.


Manage Jobs with Salt-run


Salt-run-d|grep Jobs

' Jobs.active: '

Return a 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


This shows salt-run all the commands about the job operation, and the explanation of each parameter can be viewed by salt-run-d jobs.


Salt ' minion1 ' cmd.run ' sleep 100;whoami '


^cexiting on Ctrl-c

This job ' s Jid is:

20160419174043844662

The minions is not a finished running and any remaining minions would return upon completion. "To" the "return" to "the" later run:

Salt-run Jobs.lookup_jid 20160419174043844662


Wait too long here directly ctrl-c, you can see the Jid number

Salt-run Jobs.lookup_jid 20160419174043844662


View a detailed record of this job

Salt-run Jobs.list_job 20160419174043844662

Arguments:

-Sleep 100;whoami

Function:

Cmd.run

Minions:

-Minion1

Result:

----------

Minion1:

----------

Return

Root

StartTime:

, APR 19 17:40:43.844662

Target:

Minion1

Target-type:

Glob

User:

Root

Jid

20160419174043844662


Manage Jobs with Saltstack module

The above has been introduced through the Salt-run can be the daily job management, why use module to manage the job. Salt-run the job management function is more limited, we also see above the current Salt-run does not support kill a job. Now let's start by introducing the module used by Saltstack to manage the job


To view the usage of the relevant module

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) to the named salt job ' s process

Salt ' * ' Saltutil.term_job <job id>


Let's continue with the example above to test

Salt ' minion1 ' cmd.run ' sleep 100;whoami '


Terminate command Get Jid

20160419175202067782


Using module to manage job

Salt ' minion1 ' saltutil.find_job 20160419175202067782

Minion1:

----------

Arg

-Sleep 100;whoami

Fun

Cmd.run

Jid

20160419175202067782

Pid:

25659

Ret:

Tgt:

Minion1

Tgt_type:

Glob

User

Root


We can kill this job right away.

Salt ' minion1 ' saltutil.kill_job 20160419175202067782

This article from "Eight Miles" blog, declined reprint!

Saltstack Study Notes 9-job

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.