]> git.stg.codes - stg.git/blob - functest/test.sh
Process services on daily basis.
[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 printf "Starting Stargazer... "
34
35 "$STGPATH/stargazer" "$STGPATH" >> "$LOGFILE" 2>&1 &
36
37 COUNT=""
38 while true
39 do
40     grep "Stg started successfully" "$STGPATH/stargazer.log" > /dev/null 2> /dev/null
41     if [ "$?" == "0" ]
42     then
43         break
44     fi
45     COUNT="$COUNT."
46     if [ "$COUNT" == "....." ]
47     then
48         printf "Failed to start stg in 5 sec.\n"
49         exit -1
50     fi
51     sleep 1
52 done
53
54 PID=`cat "$STGPATH/stargazer.pid"`
55 printf "Started with pid $PID\n"
56
57 printf "\nTesting admins:\n"
58 "$CURPATH/test_admins.sh" "$BASEPATH"
59 printf "\nTesting services:\n"
60 "$CURPATH/test_services.sh" "$BASEPATH"
61 printf "\n"
62
63 printf "Stopping... "
64 kill $PID
65
66 COUNT=""
67 while true
68 do
69     grep "Stg stopped successfully" "$STGPATH/stargazer.log" > /dev/null 2> /dev/null
70     if [ "$?" == "0" ]
71     then
72         break
73     fi
74     COUNT="$COUNT."
75     if [ "$COUNT" == "....." ]
76     then
77         printf "Failed to stop stg in 5 sec.\n"
78         exit -1
79     fi
80     sleep 1
81 done
82
83 printf "Stopped.\n"