Skip to content

Commit

Permalink
More ubuntu fixes... (#40)
Browse files Browse the repository at this point in the history
* Fix a few bugs in the Ubuntu init script

* Dynamically find the 'service' command path in the babysit script

* Leverate the actual init scripts for auto-restarting the agent if
necessary.

This is definitely simpler!

* A few more Ubuntu init script bug fixes.

Ensure that we error out on any failure, properly return an exit code.
This makes sure that the updated cron job to sanity check the service
works properly.

* Set the CLASSPATH more safely -- ensure packaged JARs are used first!

* Re-implement the babysit script, but with a small bugfix.

The babysit script does indeed do usefull things (verifies that the
service _should_ be running and then restarts it if its not).
  • Loading branch information
diranged authored and chaochenq committed Jul 14, 2016
1 parent f51ff40 commit 3e0a560
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
9 changes: 5 additions & 4 deletions bin/aws-kinesis-agent-babysit
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

# The cron-babysit periodically checks the status of the agent, and restart it if stopped abnormally

PATH=/sbin:/usr/sbin:/bin:/usr/bin:$PATH
DAEMON_NAME=aws-kinesis-agent
PIDFILE=/var/run/$DAEMON_NAME.pid
SERVICE="/sbin/service $DAEMON_NAME"
SERVICE="service $DAEMON_NAME"

function get_agent_pid() {
echo $(ps --ppid $(cat $PIDFILE 2>/dev/null) ho pid 2>/dev/null)
Expand All @@ -16,11 +17,11 @@ function start_agent() {
[[ -n $(get_agent_pid) ]] || exit 1
}

# Check if PID file exists.
# Check if PID file exists.
# If it does not, it means either the agent was never started or it was stopped by the user.
[[ -f $PIDFILE ]] || exit 0

# Check if the child Java process is alive. If not, we should start
[[ -n $(get_agent_pid) ]] || start_agent

exit 0
exit 0
15 changes: 9 additions & 6 deletions bin/aws-kinesis-agent.Ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
# as a daemon.
### END INIT INFO

set -e

# get init functions: status()
[ -e /lib/lsb/init-functions ] && . /lib/lsb/init-functions
. /lib/lsb/init-functions

#set -x
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON_NAME=aws-kinesis-agent
NAME=$DAEMON_NAME # ubuntu compatibility
AGENT_USER=aws-kinesis-agent-user
Expand All @@ -30,8 +32,8 @@ LOGLEVEL=${LOGLEVEL:-INFO}
ARGS=${ARGS:-}
RETVAL=0

# load any configs/environment from /etc/defaults/<name>
[ -e /etc/defaults/$DAEMON_NAME ] && . /etc/defaults/$DAEMON_NAME
# load any configs/environment from /etc/default/<name>
[ -e /etc/default/$DAEMON_NAME ] && . /etc/default/$DAEMON_NAME

# Export the settings
do_start () {
Expand Down Expand Up @@ -89,11 +91,12 @@ case "$command" in
esac
;;
restart)
$0 stop
$0 start
do_stop
do_start
;;
status)
status_of_proc -p $PIDFILE $DAEMON_NAME $NAME
exit $?
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
Expand Down
2 changes: 1 addition & 1 deletion bin/start-aws-kinesis-agent
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ LIB_DIR=$(cd "$BIN_DIR"/../share/$DAEMON_NAME/lib && pwd)
_debug_msg "BIN_DIR=${BIN_DIR}"
_debug_msg "LIB_DIR=${LIB_DIR}"
_debug_msg "PWD=${PWD}"
CLASSPATH="$JAVA_DIR"/*:"$LIB_DIR":$(find "$LIB_DIR" -type f -name \*.jar | paste -s -d:):"$CLASSPATH"
CLASSPATH="$LIB_DIR":$(find "$LIB_DIR" -type f -name \*.jar | paste -s -d:):"${JAVA_DIR}/*":"${CLASSPATH}"
_debug_msg CLASSPATH=$CLASSPATH
set +e

Expand Down

0 comments on commit 3e0a560

Please sign in to comment.