-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatcher
78 lines (57 loc) · 1.44 KB
/
watcher
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
if [ ! -f "/virtual/$USER" ]; then
mkdir /virtual/$USER
fi
if [ ! -f "/virtual/$USER/database/" ]; then
mkdir /virtual/$USER/database
fi
END=$2
for ((i=1; i<=END; i++))
do
sqlite3 /virtual/$USER/database/partition$i.db "create table if not exists urls (shortURL TEXT PRIMARY KEY, longURL TEXT NOT NULL);"
done
END=$3
for ((i=0; i<END; i++))
do
start_up[$i]=1
done
javac URLShortner.java
while true; do
END=$3
for ((i=0; i<END; i++))
do
PORT=$(($1+$i))
url="http://localhost:$PORT/healthcheck"
echo $i
response="$(curl $url)"
echo $response
if [ "$response" = "Health Normal" ]
then
start_up[$i]=0
echo "Success"
elif [ "$response" = "Server Connection error : Address already in use (Bind failed)" ]
then
echo "Port not open"
else
sqlite3 /virtual/$USER/database/SystemState.db <<-EOF
.tables
UPDATE Datacount SET count=${start_up[$i]}+count-1 WHERE partition_type IN (SELECT partition FROM Databases WHERE port=$PORT);
DELETE FROM Databases WHERE port=$PORT};
DELETE FROM Processes WHERE port=$PORT;
EOF
for host in `cat hosts`
do
ssh -o StrictHostKeyChecking=no $host < /dev/null "cd \"$CWD\"; ./watcher $1 $2 $3" &
done
java -cp ../sqlite/sqlite-jdbc-3.27.2.1.jar:. URLShortner $(($1+$i)) $2 &
fi
done
END=$2
for ((i=1; i<=END; i++))
do
if [ ! -f "/virtual/$USER/database/partition$i.db" ]; then
./dataRecovery $i
fi
done
sleep 2s
done