This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the bug when dev_setup running in 32-bit boxes
Because currently echo server uses a third party binary file which is architecture dependent, it will only work in x86_64 platform at the moment.This patch removes the third party binary and uses bash script instead to make it architecture indepentdent. Change-Id: I1477c6cd0ce9ea8f629fbb10900b923051803aac
- Loading branch information
Showing
4 changed files
with
131 additions
and
216 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
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
123 changes: 123 additions & 0 deletions
123
dev_setup/cookbooks/echo/templates/default/echoserver.erb
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,123 @@ | ||
#!/bin/bash -e | ||
|
||
ECHOSEVER_ROOT=<%= node[:echo_server][:path] %> | ||
|
||
PIDFILE=$ECHOSEVER_ROOT/run/echoserver.pid | ||
LOG_DIR=$ECHOSEVER_ROOT/logs | ||
|
||
pid_guard() { | ||
pidfile=$1 | ||
name=$2 | ||
|
||
if [ -f "$pidfile" ]; then | ||
pid=$(head -1 "$pidfile") | ||
|
||
if [ -n "$pid" ] && [ -e /proc/$pid ]; then | ||
echo "$name is already running, please stop it first" | ||
exit 1 | ||
fi | ||
|
||
echo "Removing stale pidfile..." | ||
rm $pidfile | ||
fi | ||
} | ||
|
||
wait_pidfile() { | ||
pidfile=$1 | ||
try_kill=$2 | ||
timeout=${3:-0} | ||
force=${4:-0} | ||
countdown=$(( $timeout * 10 )) | ||
|
||
if [ -f "$pidfile" ]; then | ||
pid=$(head -1 "$pidfile") | ||
|
||
if [ -z "$pid" ]; then | ||
echo "Unable to get pid from $pidfile" | ||
exit 1 | ||
fi | ||
|
||
if [ -e /proc/$pid ]; then | ||
if [ "$try_kill" = "1" ]; then | ||
echo "Killing $pidfile: $pid " | ||
kill $pid | ||
fi | ||
while [ -e /proc/$pid ]; do | ||
sleep 0.1 | ||
[ "$countdown" != '0' -a $(( $countdown % 10 )) = '0' ] && echo -n . | ||
if [ $timeout -gt 0 ]; then | ||
if [ $countdown -eq 0 ]; then | ||
if [ "$force" = "1" ]; then | ||
echo -ne "\nKill timed out, using kill -9 on $pid... " | ||
kill -9 $pid | ||
sleep 0.5 | ||
fi | ||
break | ||
else | ||
countdown=$(( $countdown - 1 )) | ||
fi | ||
fi | ||
done | ||
if [ -e /proc/$pid ]; then | ||
echo "Timed Out" | ||
else | ||
echo "Process $pid has been stopped successfully" | ||
fi | ||
else | ||
echo "Process $pid is not running" | ||
fi | ||
|
||
rm -f $pidfile | ||
else | ||
echo "Pidfile $pidfile doesn't exist" | ||
fi | ||
} | ||
|
||
kill_and_wait() { | ||
pidfile=$1 | ||
# Monit default timeout for start/stop is 30s | ||
# Append 'with timeout {n} seconds' to monit start/stop program configs | ||
timeout=${2:-25} | ||
force=${3:-1} | ||
|
||
wait_pidfile $pidfile 1 $timeout $force | ||
} | ||
|
||
start_echoserver() { | ||
echo "starting echo server" | ||
java \ | ||
-jar $ECHOSEVER_ROOT/lib/EchoServer-0.1.0.jar \ | ||
-port <%= node[:echo_server][:port] %> \ | ||
>>$LOG_DIR/echoserver.stdout.log \ | ||
2>>$LOG_DIR/echoserver.stderr.log & | ||
echo $! > $PIDFILE | ||
echo "echo server has been started successfully" | ||
} | ||
|
||
case $1 in | ||
|
||
start) | ||
pid_guard $PIDFILE "echo server" | ||
start_echoserver | ||
|
||
;; | ||
|
||
stop) | ||
kill_and_wait $PIDFILE | ||
|
||
;; | ||
|
||
restart) | ||
if [ -f "$PIDFILE" ]; then | ||
kill_and_wait $PIDFILE | ||
fi | ||
start_echoserver | ||
|
||
;; | ||
|
||
*) | ||
echo "Usage: echoserver {start|stop|restart}" | ||
|
||
;; | ||
|
||
esac |
207 changes: 0 additions & 207 deletions
207
dev_setup/cookbooks/echo/templates/default/wrapper.conf.erb
This file was deleted.
Oops, something went wrong.