-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #5791: Implementation of a command line for rudder agent #1
Merged
jooooooon
merged 1 commit into
Normation:branches/rudder/3.0
from
peckpeck:dev_5791/implementation_of_a_command_line_for_rudder_agent
Nov 24, 2014
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#!/bin/sh | ||
# | ||
# Wrapper to call rudder commands. | ||
# | ||
# All commands are taken from $BASEDIR (/opt/rudder/share/commands). | ||
# | ||
# To add a new command, just drop it in this directory with the name <role>-<command> | ||
# where <role> can be 'agent' or 'server' and <command> is your command name. | ||
# The command file is executed with remaining arguments and can be written in any executable form. | ||
# The command file should contain a line with a description of the form "# @description <your description>" | ||
# | ||
|
||
|
||
set -e | ||
BASEDIR="/opt/rudder/share/commands" | ||
|
||
role_list() { | ||
ls "${BASEDIR}" | sed 's/\([A-Za-z_]*\)-.*/\1/' | uniq | ||
} | ||
|
||
usage() { | ||
echo "" | ||
echo "Usage: rudder help" | ||
for role in `role_list` | ||
do | ||
echo " rudder ${role} <command> [parameters ...]" | ||
done | ||
echo "" | ||
echo " This is rudder generic command line interface." | ||
echo "" | ||
echo " help: this help" | ||
for role in `role_list` | ||
do | ||
echo " ${role}: rudder ${role} related commands" | ||
done | ||
echo "" | ||
} | ||
|
||
role_usage() { | ||
role="$1" | ||
echo "" | ||
echo "Usage: rudder ${role} help" | ||
echo " rudder ${role} <command> [parameters ...]" | ||
echo "" | ||
echo " Run commands on ${role}." | ||
echo "" | ||
echo " Available commands:" | ||
for file in `cd "${BASEDIR}"; find . -type f -name "${role}-*" | sort` | ||
do | ||
doc=`sed -ne "/#[ \t]*@description[ \t]*/s/#[ \t]*@description[ \t]*//p" "${BASEDIR}/${file}"` | ||
name=`echo "${file}" | sed -e "s/\.\/${role}-//"` | ||
printf " %-10s\t%s\n" "${name}" "${doc}" | ||
done | ||
echo "" | ||
} | ||
|
||
# first parameter is role parameter | ||
role=`echo "$1" | tr -C -d 'A-Za-z_'` | ||
if [ "${role}" = "help" ] || [ -z "${role}" ] | ||
then | ||
if [ -z "$2" ] | ||
then | ||
usage | ||
else | ||
role=`echo "$2" | tr -C -d 'A-Za-z_'` | ||
role_usage "${role}" | ||
fi | ||
exit 0 | ||
fi | ||
shift | ||
|
||
# test validity of role parameter | ||
for installed_role in `role_list` | ||
do | ||
if [ "${role}" = "${installed_role}" ] | ||
then | ||
role_ok="y" | ||
fi | ||
done | ||
|
||
if [ "${role_ok}" != "y" ] | ||
then | ||
echo "Unknown role '${role}'" | ||
echo "" | ||
usage | ||
exit 1 | ||
fi | ||
|
||
# second parameter is command parameter | ||
command=`echo "$1" | tr -C -d 'A-Za-z_-'` | ||
if [ "${command}" = "help" ] || [ "${command}" = "" ] | ||
then | ||
role_usage "${role}" | ||
exit 3 | ||
fi | ||
shift | ||
|
||
# test validity of command parameter | ||
if [ ! -f "${BASEDIR}/${role}-${command}" ] | ||
then | ||
echo "Command ${command} on ${role} not found" | ||
echo "" | ||
role_usage "${role}" | ||
exit 3 | ||
fi | ||
|
||
|
||
# OK GO ! | ||
exec "${BASEDIR}/${role}-${command}" "$@" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
# @description forbid rudder-agent to be run by cron or service | ||
touch /opt/rudder/etc/disable-agent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/sh | ||
# @description re-enable a disabled rudder-agent | ||
|
||
while getopts "s" opt; do | ||
case $opt in | ||
s) | ||
START=y | ||
;; | ||
esac | ||
done | ||
|
||
rm -f /opt/rudder/etc/disable-agent | ||
if [ "${START}" = "y" ] | ||
then | ||
service rudder-agent start | ||
else | ||
echo "rudder-agent has been enabled but not started, use 'service rudder-agent start' or wait for next cron run" | ||
echo "Next time, use -s option to automatically start it" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
# @description force the agent to create and send a new inventory | ||
/var/rudder/cfengine-community/bin/cf-agent -KC -D force_inventory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh | ||
# @description re-initialise the agent to make it be seen as a new node on the server | ||
|
||
# - replace ppkeys | ||
/bin/rm -f /var/rudder/cfengine-community/ppkeys/localhost* | ||
/var/rudder/cfengine-community/bin/cf-key | ||
|
||
# - generate a new uuid | ||
uuidgen > /opt/rudder/etc/uuid.hive | ||
|
||
# - resend inventory | ||
rudder agent inventory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/sh | ||
# @description reset agent status and cache | ||
|
||
# Try to remove everything that can block | ||
# - restore initial promises | ||
rsync --delete -r /opt/rudder/share/initial-promises/ /var/rudder/cfengine-community/inputs/ | ||
|
||
# - remove state | ||
/bin/rm -rf /var/rudder/cfengine-community/state/* | ||
/bin/rm -f /var/rudder/cfengine-community/*.lmdb | ||
|
||
# - remove locks | ||
/bin/rm -f /var/rudder/cfengine-community/*lock | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
# @description force run agent promises | ||
/var/rudder/cfengine-community/bin/cf-agent -KC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
# @description update promises on agent | ||
/var/rudder/cfengine-community/bin/cf-agent -KC -f failsafe.cf |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the enable command also check that cf-execd is running and start it if not? Otherwise, it's not really enabled, or it will be but only after some random delay...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be run after 5mn by cron if the user forgets to run it.
I think enable just mean enable and not run, but we can add a parameter for that.