/
serviceTest.sh
executable file
·47 lines (41 loc) · 1.09 KB
/
serviceTest.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
#!/bin/bash
########################### TESTING ############################
# For now on Mac:
# docker logs -f `docker ps -q --filter name=$SERVICE_NAME`
#
# For now on Linux:
# sudo tail -f /var/log/syslog
################################################################
# $1 == $SERVICE_NAME
# $2 == "key" being searched for to know if service is successfully runnning. If found, exit(0)
# $3 == timeout - if exceeded, service failed. exit(1)
name=$1
match=$2
timeOut=$3
START=$SECONDS
##################################### Check the operating system #########################################
if [ $(uname -s) == "Darwin" ]; then
# This is a MAC machine
command="docker logs -f `docker ps -q --filter name=$name`"
else
# This is a LINUX machine
command="sudo grep -q -m 1 "$match" /var/log/syslog"
fi
docker ps -a
declare -i counter
counter=0
while :
do
#sudo tail -n50 /var/log/syslog
$command
if [ $? -eq 0 ]; then
echo "found it"
exit 0
elif [ $counter -ge $timeOut ]; then
echo "timeout"
exit 1
fi
counter=$counter+1
#sudo tail -n1 /var/log/syslog
sleep 1
done