JunJiang江骏 bio photo

JunJiang江骏

Staff Engineer @ Ant Group. Machine Learning GDE(Google Developer Expert). Focus on machine learning platform and training framework optimization.

Twitter Google+ LinkedIn Instagram Github Weibo

Salt (4) 任务:Jobs

tags: salt

http://docs.saltstack.com/en/latest/topics/jobs/

每次通过 salt 执行一个命令(salt module) / state / highstate,salt 都建一个 job。管理在 /var/cache/salt/proc

saltutil 封装的命令

  1. running Returns the data of all running jobs that are found in the proc directory.
  2. find_job Returns specific data about a certain job based on job id.
  3. signal_job Allows for a given jid to be sent a signal.
  4. term_job Sends a termination signal (SIGTERM, 15) to the process controlling the specified job.
  5. kill_job Sends a kill signal (SIGKILL, 9) to the process controlling the specified job.

用法:

salt '*' saltutil.running

jobs runner 封装的命令

jobs runner 是专为操作 jobs 设计的命令。它的输出会比 saltutil 更易读,而且功能更多。如果你的命令是 --async 执行的,那么在知道 jid 后,就需要 looup_jid 来不断尝试去获取执行结果了。

用法:

# 相当于 saltutil.running,结果更易读
salt-run jobs.active

# 列出所有 jobs,便于查找 jid (job id number)
salt-run jobs.list_jobs

# 查看某个 job 的运行结果
salt-run jobs.lookup_jid <job id number>

comments powered by Disqus