15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/dynamodb/cli.rb', line 15
def start
%x(
if [ -z $JAVA_HOME ]; then
echo >&2 'ERROR: DynamoDBLocal requires JAVA_HOME to be set.'
fi
)
%x(
if [ ! -x $JAVA_HOME/bin/java ]; then
echo >&2 'ERROR: JAVA_HOME is set, but I do not see the java executable there.'
exit 1
fi
)
dist_dir = options[:dist_dir] || DIST_DIR
`cd #{dist_dir}`
%x(
if [ ! -f DynamoDBLocal.jar ] || [ ! -d DynamoDBLocal_lib ]; then
echo >&2 "ERROR: Could not find DynamoDBLocal files in #{dist_dir}."
exit 1
fi
)
log_dir = options[:log_dir] || LOG_DIR
`mkdir -p #{log_dir}`
puts "DynamoDB Local output will save to #{dist_dir}/#{log_dir}/"
port = options[:port] || PORT
`hash lsof 2>/dev/null && lsof -i :#{port} && { echo >&2 "Something is already listening on port #{port}; I will not attempt to start DynamoDBLocal."; exit 1; }`
`nohup $JAVA_HOME/bin/java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -delayTransientStatuses -port #{port} -inMemory 1>"#{log_dir}/output.log" 2>"#{log_dir}/error.log" &`
`PID=$!`
puts "Verifying that DynamoDBLocal actually started..."
%x(
counter=0
while [ $counter -le 5 ]; do
kill -0 $PID
if [ $? -ne 0 ]; then
echo >&2 'ERROR: DynamoDBLocal died after we tried to start it!'
exit 1
else
counter=$(($counter + 1))
sleep 1
fi
done
)
puts "DynamoDB Local started with pid #{`$PID`} listening on port #{port}."
pidfile = options[:pidfile] || PIDFILE
puts `$PID > #{pidfile}`
end
|