问题描述
我需要知道如何从其他工作中调出工作。我的目标是作业A 呼叫作业B 并发送数组参数。
基本上,职位B 包含启动/停止基础结构服务的逻辑,而职位A 包含获取所有服务和要执行的操作的逻辑。
如果不可能,您知道有其他替代方法可以做到吗?
致谢
解决方法
您有两种选择可以做到这一点。第一个方法是使用option list(您可以在文本框上选择)上定义的动作创建父作业,然后使用job reference steps上的参数将该动作传递给子作业。
基本上,子作业会评估该字符串并根据该字符串采取一些措施。我做了一个工作示例(在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>
儿童工作(服务)
httpd:
<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>
pop3:
<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,use start or stop."
fi
]]></script>
<scriptargs />
<scriptinterpreter>/bin/bash</scriptinterpreter>
</command>
</sequence>
<uuid>df9152d8-c4df-4698-b7c7-e8fdd622c59b</uuid>
</job>
</joblist>
ircd:
<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,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>
儿童工作(服务):
httpd:
<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,use start or stop."
fi
]]></script>
<scriptargs />
<scriptinterpreter>/bin/bash</scriptinterpreter>
</command>
</sequence>
<uuid>db05488e-0566-4ab9-b43e-e057a55f1198</uuid>
</job>
</joblist>
pop3:
<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,use start or stop."
fi
]]></script>
<scriptargs />
<scriptinterpreter>/bin/bash</scriptinterpreter>
</command>
</sequence>
<uuid>7285547c-99e1-4688-b180-a272327f590d</uuid>
</job>
</joblist>
ircd:
<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,use start or stop."
fi
]]></script>
<scriptargs />
<scriptinterpreter>/bin/bash</scriptinterpreter>
</command>
</sequence>
<uuid>a214976f-d8e8-4ce8-89af-d6b247b618e4</uuid>
</job>
</joblist>
如您所见,这基本上是脚本。最简单的方法是使用Rundeck Enterprise上的ruleset strategy。