Skip to content

Instantly share code, notes, and snippets.

@jooooooon
Created January 18, 2012 23:48
Show Gist options
  • Save jooooooon/1636589 to your computer and use it in GitHub Desktop.
Save jooooooon/1636589 to your computer and use it in GitHub Desktop.
body action my_bg {
background => "true";
}
body classes kept_if_else_exclusive_persist(kept, repaired, failed, persist) {
kept_returncodes => { "0" };
#repaired_returncodes => { "1", "3", "5" };
#failed_returncodes => { "7", "9" };
promise_kept => { "$(kept)" };
cancel_kept => { "$(repaired)", "$(failed)" };
promise_repaired => { "$(repaired)" };
cancel_repaired => { "$(kept)", "$(failed)" };
repair_failed => { "$(failed)" };
repair_denied => { "$(failed)" };
repair_timeout => { "$(failed)" };
cancel_notkept => { "$(kept)", "$(repaired)" };
persist_time => "$(persist)";
}
bundle agent job_scheduler {
vars:
"duration_minutes[hourly]" int => "60";
"duration_minutes[daily]" int => "1440";
&JOB_COMMAND:{command |"job_scheduler_command[&i&]" string => "&command&";
}&
&JOB_FREQUENCY:{frequency |"job_scheduler_frequency[&i&]" string => "&frequency&";
}&
&TRACKINGKEY:{uuid |"job_scheduler_uuids[&i&]" string => "&uuid&";
}&
"iterator" slist => getindices("job_scheduler_uuids");
"job_scheduler_canon_name[$(iterator)]" string => canonify("$(job_scheduler_command[$(iterator)])");
classes:
"job_scheduler_random_time_$(iterator)" expression => splayclass("$(sys.host)$(sys.ipv4)","$(job_scheduler_frequency[$(iterator)])");
commands:
"$(job_scheduler_command[$(iterator)])"
action => my_bg,
contain => in_shell,
ifvarclass => "job_scheduler_random_time_$(iterator)",
classes => kept_if_else_exclusive_persist("$(job_scheduler_canon_name[$(iterator)])_ok",
"$(job_scheduler_canon_name[$(iterator)])_repaired",
"$(job_scheduler_canon_name[$(iterator)])_failed",
"$(duration_minutes[$(job_scheduler_frequency[$(iterator)])])");
reports:
linux|windows::
# Note: if the command has not been executed (ever or since > frequency), no report will be sent until the splayclass is defined
# This will cause Rudder to report an "Unknown" status, and is by design
"@@jobScheduler@@result_success@@$(job_scheduler_uuids[$(iterator)])@@jobScheduler@@None@@$(g.execRun)##$(g.uuid)@#Job return a success return code on last completed execution ($(job_scheduler_command[$(iterator)]))"
ifvarclass => "$(job_scheduler_canon_name[$(iterator)])_ok";
"@@jobScheduler@@result_repaired@@$(job_scheduler_uuids[$(iterator)])@@jobScheduler@@None@@$(g.execRun)##$(g.uuid)@#Job returned a repaired return code on last completed execution ($(job_scheduler_command[$(iterator)]))"
ifvarclass => "$(job_scheduler_canon_name[$(iterator)])_repaired";
"@@jobScheduler@@result_error@@$(job_scheduler_uuids[$(iterator)])@@jobScheduler@@None@@$(g.execRun)##$(g.uuid)@#Job failed on last completed execution ($(job_scheduler_command[$(iterator)]))"
ifvarclass => "$(job_scheduler_canon_name[$(iterator)])_failed";
"@@jobScheduler@@log_info@@$(job_scheduler_uuids[$(iterator)])@@jobScheduler@@None@@$(g.execRun)##$(g.uuid)@#Job has been launched ($(job_scheduler_command[$(iterator)])), result will be reported on next run"
ifvarclass => "job_scheduler_random_time_$(iterator)";
}
<!--
Copyright 2012 Normation SAS
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, Version 3.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<POLICY name="Job scheduler">
<DESCRIPTION>Runs commands, optionally in the background, optionally with a random distribution across nodes</DESCRIPTION>
<COMPATIBLE>
<OS>Every OS</OS>
<AGENT version=">= 3.1.5">cfengine-community</AGENT>
</COMPATIBLE>
<BUNDLES>
<NAME>job_scheduler</NAME>
</BUNDLES>
<TMLS>
<TML name="job_scheduler"/>
</TMLS>
<SECTIONS>
<!-- general Section -->
<SECTION name="Job" multivalued="true">
<INPUT>
<NAME>JOB_COMMAND</NAME>
<DESCRIPTION>Command to run</DESCRIPTION>
<CONSTRAINT>
<TYPE>string</TYPE>
</CONSTRAINT>
</INPUT>
<SELECT1>
<NAME>JOB_FREQUENCY</NAME>
<DESCRIPTION>Run the command randomly every</DESCRIPTION>
<LONGDESCRIPTION>The command will be run on all nodes, with execution time spread over the period selected. Execution time will remain the same on each node, but will appear random across all nodes. There is no way of specifying when in the day or the hour to start</LONGDESCRIPTION>
<ITEM>
<LABEL>Hour</LABEL>
<VALUE>hourly</VALUE>
</ITEM>
<ITEM>
<LABEL>Day</LABEL>
<VALUE>daily</VALUE>
</ITEM>
<CONSTRAINT>
<DEFAULT>string</DEFAULT>
</CONSTRAINT>
</SELECT1>
</SECTION>
</SECTIONS>
</POLICY>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment