Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Fix the bug when dev_setup running in 32-bit boxes
Browse files Browse the repository at this point in the history
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
bluesalt committed Jul 24, 2012
1 parent 2b107a4 commit 8b4b17b
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 216 deletions.
4 changes: 2 additions & 2 deletions dev_setup/cookbooks/echo/attributes/default.rb
Expand Up @@ -6,7 +6,7 @@
default[:echo_node][:index] = "0"
default[:echo_node][:token] = "changeechotoken"

default[:echo_server][:id] = "eyJvaWQiOiI0ZTRlNzhiY2E2MWUxMjEyMDRlNGU4NmVlYmU1OTEwNGZmMDQ3%0AYTExOGEyNiIsInNpZyI6Im9wNVBMcVZaV1lFVVZ2bkhpaDFORnBVSENjMD0i%0AfQ==%0A"
default[:echo_server][:checksum] = "a1a3e89ae72ceb8f05106ad0666e4638077591090f28797ec240ded4956b610e"
default[:echo_server][:id] = "eyJvaWQiOiI0ZTRlNzhiY2ExMWUxMjEwMDRlNGU3ZDUxMWY4MjEwNTAwOTA0%0ANGIxMDRkMCIsInNpZyI6Ikd2RFlpUlh2bEhrdnoxT3pyTVJhYlhUcjJyMD0i%0AfQ==%0A"
default[:echo_server][:checksum] = "a4d5976dfff5d0c9e14fd6eaaa587fcc2543f18c88e3f28960cd18d04c1fa7c9"
default[:echo_server][:path] = File.join(node[:deployment][:home], "deploy", "echoserver")
default[:echo_server][:port] = 5002
13 changes: 6 additions & 7 deletions dev_setup/cookbooks/echo/recipes/default.rb
Expand Up @@ -18,24 +18,23 @@
code <<-EOH
unzip #{echoserver_tarball_path} -d /tmp
cp -r /tmp/echoserver #{File.join(node[:deployment][:home], 'deploy')}
ln -s -t /etc/init.d/ #{File.join(node[:echo_server][:path], 'bin', 'echoserver')}
ln -s -t /etc/init.d/ #{File.join(node[:echo_server][:path], 'echoserver')}
EOH
not_if do
::File.exists?(File.join(node[:echo_server][:path], 'bin', 'echoserver'))
::File.exists?(File.join(node[:echo_server][:path], 'echoserver'))
end
end

template File.join(node[:echo_server][:path], 'conf', 'wrapper.conf') do
source "wrapper.conf.erb"
template File.join(node[:echo_server][:path], 'echoserver') do
source "echoserver.erb"
owner "root"
group "root"
mode "0600"
notifies :restart, "service[echoserver]"
mode "0755"
end

service "echoserver" do
supports :status => true, :restart => true
action [ :enable, :start ]
action [ :enable, :restart ]
end
else
Chef::Log.error("Installation of echo server not supported on this platform.")
Expand Down
123 changes: 123 additions & 0 deletions dev_setup/cookbooks/echo/templates/default/echoserver.erb
@@ -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 dev_setup/cookbooks/echo/templates/default/wrapper.conf.erb

This file was deleted.

0 comments on commit 8b4b17b

Please sign in to comment.