-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #5791: Implementation of a command line for rudder agent
- Loading branch information
Showing
8 changed files
with
161 additions
and
0 deletions.
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=`grep "# @description" "${BASEDIR}/${file}" | sed -e "s/#[ \t]*@description[ \t]*//"` | ||
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,13 @@ | ||
#!/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 | ||
[ "${START}" = "y" ] && service rudder-agent start |
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 |