-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwikifundi_management.sh
executable file
·169 lines (142 loc) · 2.07 KB
/
wikifundi_management.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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/bash
NB_TRY=10
PAUSE=5
PROJECT="wikifundi"
function running_status
{
RUNNING=0;
for i in `sloppy show -r $PROJECT | jq .[0].apps[].status[0]`
do
if [ ! "$i" = "\"running\"" ]
then
RUNNING=1 ;
fi
done
}
function wait_running
{
RUNNING=1;
while [ $RUNNING -eq 1 ]
do
echo "in process ..."
running_status
sleep $PAUSE
done
echo "all instances running !"
}
function get_list_apps
{
APPS=`sloppy show -r $PROJECT | jq .[0].apps[].id | cut -d \" -f 2`
}
function restart_app
{
echo "restart $app"
sloppy restart $PROJECT/$PROJECT/$app
}
function delete_app
{
echo "delete $app"
sloppy delete $PROJECT/$PROJECT/$app
}
function restart_all
{
get_list_apps
for app in $APPS
do
restart_app
sleep $PAUSE
done
}
function get_app_from_lang
{
lang=$1
app="wikifundi-$lang"
}
function restart
{
lang=$1
if [ -z $lang ]
then
restart_all
else
get_app_from_lang $lang
restart_app
fi
}
function sloppy_change
{
PARAMS=$1
sloppy change $PARAMS
}
function delete_all
{
if [ "$1" == "force" ]
then
rep="delete_all"
else
echo "type delete_all to confirm"
read rep
fi
if [ $rep == "delete_all" ]
then
get_list_apps
for app in $APPS
do
delete_app
sleep $PAUSE
done
fi
}
function partial_mirroring
{
sloppy_change sloppy-partial-mirroring.json
wait_running
restart_all
}
function full_mirroring
{
for i in `seq 1 $NB_TRY`
do
echo "Try to reset all #$i"
delete_all "force"
sleep $PAUSE
sleep $PAUSE
sleep $PAUSE
sleep $PAUSE
if sloppy_change sloppy-full-mirroring.json
then
return
fi
done
}
function cron
{
#run full mirroring only the sunday
if [ `date +%w` == "0" ]
then
full_mirroring
else
partial_mirroring
fi
}
ACTION=$1
case $ACTION in
restart)
restart $2
;;
full_mirroring)
full_mirroring
;;
partial_mirroring)
partial_mirroring
;;
wait_running)
wait_running
;;
delete_all)
delete_all $2
;;
cron)
cron
;;
esac