-
Notifications
You must be signed in to change notification settings - Fork 12
/
DHuS_ingestion_restarter.sh
157 lines (101 loc) · 2.86 KB
/
DHuS_ingestion_restarter.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
#/bin/bash!
UNATTENDED="";
DIR_1=$1;
DIR_2=$2;
DIR_3=$3;
DIR_4=$4;
UNATTENDED=$5;
DIR=pippo;
COUNTER=0;
function wait_inbox_empty {
DIR=${1};
COUNTER=0;
echo "Waiting for Inbox " $DIR " to be empty"
while [ "$(ls "$DIR" |grep ".zip")" != "" ];
do echo `date -u +"%Y-%m-%d %H:%M:%S UTC"` "Not Processing; waiting for " $DIR " to be empty [ `find $DIR/ -name *.zip |wc -l` ]" ;
let COUNTER=COUNTER+1;
if ! (( $COUNTER % 6 )) ; then
echo "$DIR is still not empty after 20 minutes...aborting reboot";
exit 1;
else
sleep 2;
done
}
function Start_DHuS {
echo "Starting DHuS instance" && systemctl --user start dhus.service;
#while [ "$(grep "Server is ready" /data/dhus-current/logs/dhus-s2rep-dhus-master??.log)" = "" ]; do echo `date -u +"%Y-%m-%d %H:%M:%S UTC"` "Waiting for DHuS Ready" ; sleep 5; done
echo "Waiting for DHuS instance going up"
( tail -f -n0 /data/dhus-current/logs/dhus-s2rep-dhus-master??.log & ) | grep -q "Server is ready";
echo "DHuS started at `date -u +"%Y-%m-%d %H:%M:%S UTC"`";
}
function Stop_DHuS {
STATUS_DHUS="";
echo "";
echo "Stopping DHuS instance with a 120s timeout";
timeout 120 systemctl --user stop dhus.service;
STATUS_DHUS=`ps -ef | grep java | grep -v grep`;
if [ -z "$STATUS_DHUS" ]; then
echo "";
echo "DHuS has been STOPPED";
echo "";
else
echo "";
echo "ERROR!!!! DHuS did not STOP correctly";
echo "";
exit 1;
fi
}
function mainmenu {
echo ""
echo "Press y to start DHuS"
echo "Press q to exit script"
echo ""
read -n 1 -p "Input Selection:" menuinput
if [ "$menuinput" = "y" ]; then
Start_DHuS;
elif [ "$menuinput" = "q" ]; then
exit 0
else
echo ""
echo "You have entered an invalid selection!"
echo "Please try again!"
echo ""
echo "Press any key to continue..."
read -n 1
clear
mainmenu
fi
}
if [ -z "$DIR_1" ] || [ -z "$DIR_2" ] || [ -z "$DIR_3" ] || [ -z "$DIR_4" ];
then
echo "ERROR: Usage: ./This_Script and four DHuS_Inbox_Dirs Exiting...";
exit 1;
fi
echo "Commenting crontab file";
crontab -l > ~/crontab.bak; crontab -l | sed "s/^\(.*ingestion_regulator.*\)$/#MAINTENANCE\1/g" | crontab -;
#crontab -l > ~/crontab.bak; grep -v ingestion_regulator ~/crontab.bak | crontab -;
sleep 5;
wait_inbox_empty $DIR_1;
wait_inbox_empty $DIR_2;
wait_inbox_empty $DIR_3;
wait_inbox_empty $DIR_4;
sleep 5;
echo "Stopping DHuS instance `date -u +"%Y-%m-%d %H:%M:%S UTC"`";
Stop_DHuS;
if [ "$UNATTENDED" = "UNATTENDED" ]; then
Start_DHuS;
elif [ "$UNATTENDED" = "INTERACTIVE" ]; then
mainmenu;
else
echo ""
echo "You did not specify if UNATTENDED or INTERACTIVE"
echo ""
echo "Assuming INTERACTIVE...."
echo ""
mainmenu
fi
echo "";
echo "Decommenting Crontab file";
cat ~/crontab.bak | crontab -;
echo "Done!";
exit 0;