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
|
# 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 #{options[:dist_dir]}`
%x(
if [ ! -f DynamoDBLocal.jar ] || [ ! -d DynamoDBLocal_lib ]; then
echo >&2 "ERROR: Could not find DynamoDBLocal files in #{options[:dist_dir]}."
exit 1
fi
)
`mkdir -p #{options[:log_dir]}`
puts "DynamoDB Local output will save to #{options[:dist_dir]}/#{options[:log_dir]}/"
`hash lsof 2>/dev/null && lsof -i :#{options[:port]} && { echo >&2 "Something is already listening on port #{options[: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 #{options[:port]} -inMemory 1>"#{options[:log_dir]}/output.log" 2>"#{options[: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 #{options[:port]}."
puts `$PID > #{options[:pidfile]}`
end
|