繁体   English   中英

Rundeck - 工作调用其他工作

[英]Rundeck - Job call other job

我需要知道如何从其他工作中调用工作。 我的目标是Job A调用Job B并发送一个数组 param

基本上,作业 B包含用于启动/停止基础设施服务的逻辑,而作业 A包含用于获取所有服务和要执行的操作的逻辑。

如果不可能,您知道有什么替代方法可以做到吗?

问候

你有两个选择来做到这一点。 第一个是使用在选项列表(您可以使用文本框选择)上定义的操作创建父作业,并使用作业参考步骤上的参数将该操作传递给子作业。

基本上,子作业评估该字符串并根据该字符串采取一些行动。 我做了一个工作示例(在 Rundeck 3.3.3 上测试)。

家长工作:

<joblist>
  <job>
    <context>
      <options preserveOrder='true'>
        <option delimiter=',' enforcedvalues='true' multivalued='true' name='services' values='stop_httpd,stop_ircd,stop_pop3,start_httpd,start_ircd,start_pop3' valuesListDelimiter=','>
          <label>Action to your services</label>
        </option>
      </options>
    </context>
    <defaultTab>nodes</defaultTab>
    <description></description>
    <executionEnabled>true</executionEnabled>
    <id>5c6e9603-6adf-4732-8b33-4e92068f1dcb</id>
    <loglevel>INFO</loglevel>
    <name>ParentJob</name>
    <nodeFilterEditable>false</nodeFilterEditable>
    <plugins />
    <scheduleEnabled>true</scheduleEnabled>
    <sequence keepgoing='false' strategy='node-first'>
      <command>
        <description>only for debug</description>
        <exec>echo "Services selected: ${option.services}"</exec>
        <plugins />
      </command>
      <command>
        <jobref name='HttpService' nodeStep='true'>
          <arg line='-action ${option.services}' />
          <uuid>58ca8e25-4473-4ba3-89be-29cfe6487b22</uuid>
        </jobref>
      </command>
      <command>
        <jobref group='services' name='IrcdService' nodeStep='true'>
          <arg line='-action ${option.services}' />
          <uuid>ea2b2e0f-f140-4716-a207-1690a42c2a59</uuid>
        </jobref>
      </command>
      <command>
        <jobref group='services' name='Pop3Service' nodeStep='true'>
          <arg line='-action ${option.services}' />
          <uuid>df9152d8-c4df-4698-b7c7-e8fdd622c59b</uuid>
        </jobref>
      </command>
    </sequence>
    <uuid>5c6e9603-6adf-4732-8b33-4e92068f1dcb</uuid>
  </job>
</joblist>

儿童工作(服务):

网址:

<joblist>
  <job>
    <context>
      <options preserveOrder='true'>
        <option name='action' />
      </options>
    </context>
    <defaultTab>nodes</defaultTab>
    <description></description>
    <executionEnabled>true</executionEnabled>
    <group>services</group>
    <id>58ca8e25-4473-4ba3-89be-29cfe6487b22</id>
    <loglevel>INFO</loglevel>
    <name>HttpService</name>
    <nodeFilterEditable>false</nodeFilterEditable>
    <plugins />
    <scheduleEnabled>true</scheduleEnabled>
    <sequence keepgoing='false' strategy='node-first'>
      <command>
        <fileExtension>.sh</fileExtension>
        <script><![CDATA[# current service
service=httpd

# check if the service is running
check_service () {
    # just a simulation, the service is up
    echo up
}

# up / down logic
if [[ @option.action@ == *"start_httpd"* ]]; then
    if [[ $(check_service) == "up" ]]; then
        echo "Nothing to do, the service is running."
    else
        echo "starting $service service..."
        echo "$service started succefully"
    fi
elif [[ @option.action@ == *"stop_httpd"* ]]; then
    if [[ $(check_service) == "down" ]]; then
        echo "Nothing to do, the service is down."
    else
        echo "stopping $service service..."
        echo "$service stopped succefully"
    fi
else
    echo "Parameter not recognized, use start or stop."
fi
]]></script>
        <scriptargs />
        <scriptinterpreter>/bin/bash</scriptinterpreter>
      </command>
    </sequence>
    <uuid>58ca8e25-4473-4ba3-89be-29cfe6487b22</uuid>
  </job>
</joblist>

流行音乐3:

<joblist>
  <job>
    <context>
      <options preserveOrder='true'>
        <option name='action' />
      </options>
    </context>
    <defaultTab>nodes</defaultTab>
    <description></description>
    <executionEnabled>true</executionEnabled>
    <group>services</group>
    <id>df9152d8-c4df-4698-b7c7-e8fdd622c59b</id>
    <loglevel>INFO</loglevel>
    <name>Pop3Service</name>
    <nodeFilterEditable>false</nodeFilterEditable>
    <plugins />
    <scheduleEnabled>true</scheduleEnabled>
    <sequence keepgoing='false' strategy='node-first'>
      <command>
        <fileExtension>.sh</fileExtension>
        <script><![CDATA[# current service
service=pop3

# check if the service is running
check_service () {
    # just a simulation, the service is up
    echo up
}

# up / down logic
if [[ @option.action@ == *"start_pop3"* ]]; then
    if [[ $(check_service) == "up" ]]; then
        echo "Nothing to do, the service is running."
    else
        echo "starting $service service..."
        echo "$service started succefully"
    fi
elif [[ @option.action@ == *"stop_pop3"* ]]; then
    if [[ $(check_service) == "down" ]]; then
        echo "Nothing to do, the service is down."
    else
        echo "stopping $service service..."
        echo "$service stopped succefully"
    fi
else
    echo "Parameter not recognized, use start or stop."
fi
]]></script>
        <scriptargs />
        <scriptinterpreter>/bin/bash</scriptinterpreter>
      </command>
    </sequence>
    <uuid>df9152d8-c4df-4698-b7c7-e8fdd622c59b</uuid>
  </job>
</joblist>

红外线:

<joblist>
  <job>
    <context>
      <options preserveOrder='true'>
        <option name='action' />
      </options>
    </context>
    <defaultTab>nodes</defaultTab>
    <description></description>
    <executionEnabled>true</executionEnabled>
    <group>services</group>
    <id>ea2b2e0f-f140-4716-a207-1690a42c2a59</id>
    <loglevel>INFO</loglevel>
    <name>IrcdService</name>
    <nodeFilterEditable>false</nodeFilterEditable>
    <plugins />
    <scheduleEnabled>true</scheduleEnabled>
    <sequence keepgoing='false' strategy='node-first'>
      <command>
        <fileExtension>.sh</fileExtension>
        <script><![CDATA[# current service
service=ircd

# check if the service is running
check_service () {
    # just a simulation, the service is up
    echo up
}

# up / down logic
if [[ @option.action@ == *"start_ircd"* ]]; then
    if [[ $(check_service) == "up" ]]; then
        echo "Nothing to do, the service is running."
    else
        echo "starting $service service..."
        echo "$service started succefully"
    fi
elif [[ @option.action@ == *"stop_ircd"* ]]; then
    if [[ $(check_service) == "down" ]]; then
        echo "Nothing to do, the service is down."
    else
        echo "stopping $service service..."
        echo "$service stopped succefully"
    fi
else
    echo "Parameter not recognized, use start or stop."
fi
]]></script>
        <scriptargs />
        <scriptinterpreter>/bin/bash</scriptinterpreter>
      </command>
    </sequence>
    <uuid>ea2b2e0f-f140-4716-a207-1690a42c2a59</uuid>
  </job>
</joblist>

另一种方法是使用带有服务名称的类似操作列表,并在父作业上放置一个 bash 脚本迭代,该脚本通过RDCLI调用服务。 停止服务的示例:

家长工作:

<joblist>
  <job>
    <context>
      <options preserveOrder='true'>
        <option delimiter=',' enforcedvalues='true' multivalued='true' name='services' values='httpd,ircd,pop3' valuesListDelimiter=','>
          <label>Services to Stop</label>
        </option>
      </options>
    </context>
    <defaultTab>nodes</defaultTab>
    <description></description>
    <executionEnabled>true</executionEnabled>
    <id>bb1206e8-f00c-4aa6-b7de-71c2fe8a43b1</id>
    <loglevel>INFO</loglevel>
    <name>StopServices</name>
    <nodeFilterEditable>false</nodeFilterEditable>
    <plugins />
    <scheduleEnabled>true</scheduleEnabled>
    <sequence keepgoing='false' strategy='node-first'>
      <command>
        <fileExtension>.sh</fileExtension>
        <script><![CDATA[#!/bin/sh

echo "Services to stop: @option.services@"

DataList=@option.services@

Field_Separator=$IFS

# set comma as internal field separator for the string list
IFS=,
for val in $DataList;
    do
        rd run -p @job.project@ -j $val -- -opt stop
        sleep 2
    done 

IFS=$Field_Separator]]></script>
        <scriptargs />
        <scriptinterpreter>/bin/sh</scriptinterpreter>
      </command>
    </sequence>
    <uuid>bb1206e8-f00c-4aa6-b7de-71c2fe8a43b1</uuid>
  </job>
</joblist>

童工(服务):

网址:

<joblist>
  <job>
    <context>
      <options preserveOrder='true'>
        <option name='opt' />
      </options>
    </context>
    <defaultTab>nodes</defaultTab>
    <description>Apache httpd Service.</description>
    <executionEnabled>true</executionEnabled>
    <group>services</group>
    <id>db05488e-0566-4ab9-b43e-e057a55f1198</id>
    <loglevel>INFO</loglevel>
    <name>httpd</name>
    <nodeFilterEditable>false</nodeFilterEditable>
    <plugins />
    <scheduleEnabled>true</scheduleEnabled>
    <sequence keepgoing='false' strategy='node-first'>
      <command>
        <fileExtension>.sh</fileExtension>
        <script><![CDATA[# current service
service=httpd

# check if the service is running
check_service () {
    # just a simulation, the service is up
    echo up
}

# up / down logic
if [ @option.opt@ == "start" ]; then
    if [ $(check_service) == "up" ]; then
        echo "Nothing to do, the service is running."
    else
        echo "starting $service service..."
        echo "$service started succefully"
    fi
elif [ @option.opt@ == "stop" ]; then
    if [ $(check_service) == "down" ]; then
        echo "Nothing to do, the service is down."
    else
        echo "stopping $service service..."
        echo "$service stopped succefully"
    fi
else
    echo "Parameter not recognized, use start or stop."
fi
]]></script>
        <scriptargs />
        <scriptinterpreter>/bin/bash</scriptinterpreter>
      </command>
    </sequence>
    <uuid>db05488e-0566-4ab9-b43e-e057a55f1198</uuid>
  </job>
</joblist>

流行音乐3:

<joblist>
  <job>
    <context>
      <options preserveOrder='true'>
        <option name='opt' />
      </options>
    </context>
    <defaultTab>nodes</defaultTab>
    <description>Dovecot pop3 Service.</description>
    <executionEnabled>true</executionEnabled>
    <group>services</group>
    <id>7285547c-99e1-4688-b180-a272327f590d</id>
    <loglevel>INFO</loglevel>
    <name>pop3</name>
    <nodeFilterEditable>false</nodeFilterEditable>
    <plugins />
    <scheduleEnabled>true</scheduleEnabled>
    <sequence keepgoing='false' strategy='node-first'>
      <command>
        <fileExtension>.sh</fileExtension>
        <script><![CDATA[# current service
service=pop3

# check if the service is running
check_service () {
    # just a simulation, the service is up
    echo up
}

# up / down logic
if [ @option.opt@ == "start" ]; then
    if [ $(check_service) == "up" ]; then
        echo "Nothing to do, the service is running."
    else
        echo "starting $service service..."
        echo "$service started succefully"
    fi
elif [ @option.opt@ == "stop" ]; then
    if [ $(check_service) == "down" ]; then
        echo "Nothing to do, the service is down."
    else
        echo "stopping $service service..."
        echo "$service stopped succefully"
    fi
else
    echo "Parameter not recognized, use start or stop."
fi
]]></script>
        <scriptargs />
        <scriptinterpreter>/bin/bash</scriptinterpreter>
      </command>
    </sequence>
    <uuid>7285547c-99e1-4688-b180-a272327f590d</uuid>
  </job>
</joblist>

红外线:

<joblist>
  <job>
    <context>
      <options preserveOrder='true'>
        <option name='opt' />
      </options>
    </context>
    <defaultTab>nodes</defaultTab>
    <description>IRC Daemon Service</description>
    <executionEnabled>true</executionEnabled>
    <group>services</group>
    <id>a214976f-d8e8-4ce8-89af-d6b247b618e4</id>
    <loglevel>INFO</loglevel>
    <name>ircd</name>
    <nodeFilterEditable>false</nodeFilterEditable>
    <plugins />
    <scheduleEnabled>true</scheduleEnabled>
    <sequence keepgoing='false' strategy='node-first'>
      <command>
        <fileExtension>.sh</fileExtension>
        <script><![CDATA[# current service
service=ircd

# check if the service is running
check_service () {
    # just a simulation, the service is up
    echo up
}

# up / down logic
if [ @option.opt@ == "start" ]; then
    if [ $(check_service) == "up" ]; then
        echo "Nothing to do, the service is running."
    else
        echo "starting $service service..."
        echo "$service started succefully"
    fi
elif [ @option.opt@ == "stop" ]; then
    if [ $(check_service) == "down" ]; then
        echo "Nothing to do, the service is down."
    else
        echo "stopping $service service..."
        echo "$service stopped succefully"
    fi
else
    echo "Parameter not recognized, use start or stop."
fi
]]></script>
        <scriptargs />
        <scriptinterpreter>/bin/bash</scriptinterpreter>
      </command>
    </sequence>
    <uuid>a214976f-d8e8-4ce8-89af-d6b247b618e4</uuid>
  </job>
</joblist>

如您所见,这基本上是脚本编写。 最简单的方法是使用 Rundeck Enterprise 上提供的规则集策略

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM