]> git.stg.codes - stg.git/blob - functest/test.sh
Fixed services test.
[stg.git] / functest / test.sh
1 #!/bin/sh
2
3 BASEPATH=$1
4
5 if [ "$BASEPATH" == "" ]
6 then
7     printf "Usage: $0 <path>\n"
8     exit -1
9 fi
10
11 if [ ! -d "$BASEPATH" ]
12 then
13     printf "Path '$BASEPATH' does not exist or not a directory.\n"
14     exit -1
15 fi
16
17 STGPATH="$BASEPATH/stg/projects/stargazer"
18
19 cp "stuff/stargazer-files.conf" "$STGPATH/stargazer.conf"
20 cp "stuff/rules" "$STGPATH/"
21 cp "stuff/OnConnect" "$STGPATH/"
22 cp "stuff/OnDisconnect" "$STGPATH/"
23 cp "stuff/OnChange" "$STGPATH/"
24 cp -R "stuff/db-stub" "$STGPATH/db"
25
26 sed -i "s|-STG-PATH-|$STGPATH|g" "$STGPATH/stargazer.conf"
27
28 CURPATH=`pwd`
29 LOGFILE="$CURPATH/"`date "+%Y-%m-%d-%H%M%S.console.log"`
30
31 cd "$STGPATH"
32
33 "$STGPATH/stargazer" "$STGPATH" >> "$LOGFILE" 2>&1 &
34
35 COUNT=""
36 while true
37 do
38     grep "Stg started successfully" "$STGPATH/stargazer.log" > /dev/null 2> /dev/null
39     if [ "$?" == "0" ]
40     then
41         break
42     fi
43     COUNT="$COUNT."
44     if [ "$COUNT" == "....." ]
45     then
46         printf "Failed to start stg in 5 sec.\n"
47         exit -1
48     fi
49     sleep 1
50 done
51
52 PID=`cat "$STGPATH/stargazer.pid"`
53 printf "Started with pid $PID\n"
54
55 "$CURPATH/test_admins.sh" "$BASEPATH"
56 "$CURPATH/test_services.sh" "$BASEPATH"
57
58 printf "Stopping...\n"
59 kill $PID
60
61 COUNT=""
62 while true
63 do
64     grep "Stg stopped successfully" "$STGPATH/stargazer.log" > /dev/null 2> /dev/null
65     if [ "$?" == "0" ]
66     then
67         break
68     fi
69     COUNT="$COUNT."
70     if [ "$COUNT" == "....." ]
71     then
72         printf "Failed to stop stg in 5 sec.\n"
73         exit -1
74     fi
75     sleep 1
76 done
77
78 printf "Stopped.\n"