Skip to content

Commit

Permalink
Fixes #8076: rudder agent status
Browse files Browse the repository at this point in the history
  • Loading branch information
peckpeck committed Mar 17, 2016
1 parent b351ee0 commit 31628b0
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 24 deletions.
30 changes: 6 additions & 24 deletions share/commands/agent-enable
Expand Up @@ -13,6 +13,7 @@
. "${BASEDIR}/../lib/common.sh"

QUIET=false
OPTIONS=""

while getopts "sqc" opt; do
case $opt in
Expand All @@ -21,39 +22,20 @@ while getopts "sqc" opt; do
;;
q)
QUIET=true
OPTION="${OPTIONS} -q"
;;
c)
clear_colors
OPTION="${OPTIONS} -c"
;;
esac
done

rm -f /opt/rudder/etc/disable-agent
if [ -x /usr/bin/startsrc ]
then
CMD="startsrc -s rudder-agent"
elif [ -x /usr/sbin/service ]
then
CMD="service rudder-agent start"
elif [ -x /etc/init.d/rudder-agent ]
then
CMD="/etc/init.d/rudder-agent start"
fi
if [ "${START}" = "y" ]
then
if [ -n "${CMD}" ]
then
$CMD
else
printf "${RED}error${NORMAL}: Don't know how to start rudder agent.\n" 1>&2
echo "Agent not started !" 1>&2
fi
[ "$QUIET" = false ] && printf "${GREEN}ok${NORMAL}: Rudder agent has been enabled.\n"
"${BASEDIR}/agent-start" ${OPTIONS}
else
if [ -n "${CMD}" ]
then
[ "$QUIET" = false ] && printf "${GREEN}ok${NORMAL}: Rudder agent has been enabled but not started, use '$CMD' or wait for next cron run.\n"
[ "$QUIET" = false ] && echo "You can use the -s option to automatically start it"
else
[ "$QUIET" = false ] && printf "${GREEN}ok${NORMAL}: Rudder agent has been enabled but not started, wait for next cron run.\n"
fi
[ "$QUIET" = false ] && printf "${GREEN}ok${NORMAL}: Rudder agent has been enabled but not started, wait for next cron run.\n"
fi
27 changes: 27 additions & 0 deletions share/commands/agent-start
@@ -0,0 +1,27 @@
#!/bin/sh
# @description start the agent
# @man Start the agent service using the appropriate service manager.
# @man +
# @man *Options*:
# @man +
# @man *-q*: run the agent in quiet mode (display only error messages)
# @man +
# @man *-c*: run the agent without color output

. "${BASEDIR}/../lib/common.sh"

QUIET=false

while getopts "qc" opt; do
case $opt in
q)
QUIET=true
;;
c)
clear_colors
;;
esac
done

service_action "rudder-agent" "start"
exit $?
26 changes: 26 additions & 0 deletions share/commands/agent-status
@@ -0,0 +1,26 @@
#!/bin/sh
# @description show the agent status
# @man +
# @man *Options*:
# @man +
# @man *-q*: run the agent in quiet mode (display only error messages)
# @man +
# @man *-c*: run the agent without color output

. "${BASEDIR}/../lib/common.sh"

QUIET=false

while getopts "qc" opt; do
case $opt in
q)
QUIET=true
;;
c)
clear_colors
;;
esac
done

service_action "rudder-agent" "status"
exit $?
27 changes: 27 additions & 0 deletions share/commands/agent-stop
@@ -0,0 +1,27 @@
#!/bin/sh
# @description stop the agent
# @man Stop the agent service using the appropriate service manager.
# @man +
# @man *Options*:
# @man +
# @man *-q*: run the agent in quiet mode (display only error messages)
# @man +
# @man *-c*: run the agent without color output

. "${BASEDIR}/../lib/common.sh"

QUIET=false

while getopts "qc" opt; do
case $opt in
q)
QUIET=true
;;
c)
clear_colors
;;
esac
done

service_action "rudder-agent" "stop"
exit $?
33 changes: 33 additions & 0 deletions share/lib/common.sh
Expand Up @@ -14,6 +14,39 @@ clear_colors() {
NORMAL=""
}

service_action() {
service="$1"
action="$2"

if [ -x /usr/sbin/service ]; then
CMD="service ${service} ${action}"
elif [ -x /etc/init.d/${service} ]; then
CMD="/etc/init.d/${service} ${action}"
elif [ "${action}" = "start" ] && [ -x /usr/bin/startsrc ]; then
CMD="startsrc -s ${service}"
elif [ "${action}" = "stop" ] && [ -x /usr/bin/stopsrc ]; then
CMD="stopsrc -s ${service}"
fi

if [ -n "${CMD}" ]
then
$CMD
RET="$?"
if [ "${action}" = "start" ] || [ "${action}" = "stop" ]; then
if [ $RET -eq 0 ]
then
[ "$QUIET" = false ] && printf "${GREEN}ok${NORMAL}: service ${service} has been ${action}ed\n"
else
[ "$QUIET" = false ] && printf "${RED}error${NORMAL}: service ${service} could not be ${action}ed\n"
fi
fi
return $RET
else
printf "${RED}error${NORMAL}: Don't know how to ${action} ${service}.\n" 1>&2
return 1
fi
}

# Colors configuration (enable colors only if stdout is a terminal)
if [ -t 1 ]; then
COLOR="-Calways"
Expand Down

0 comments on commit 31628b0

Please sign in to comment.