-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcacheClear.sh
More file actions
157 lines (128 loc) · 4.49 KB
/
Copy pathcacheClear.sh
File metadata and controls
157 lines (128 loc) · 4.49 KB
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
. /etc/init.d/functions
LOG="cacheClear.log"
STARTTIME=`date +"%y-%m-%d_%H-%m-%s"`
echo $STARTTIME > $LOG
echo `hostname` >> $LOG
# Use step(), try(), and next() to perform a series of commands and print
# [ OK ] or [FAILED] at the end. The step as a whole fails if any individual
# command fails.
#
step() {
echo -n -e "$@"
echo -e "\n\nSTEP - $@">> $LOG
STEP_OK=0
[[ -w /tmp ]] && echo $STEP_OK > /tmp/step.$$
}
try() {
# Check for `-b' argument to run command in the background.
local BG=
[[ $1 == -b ]] && { BG=1; shift; }
[[ $1 == -- ]] && { shift; }
# Run the command.
echo -e "$@" >> $LOG
if [[ -z $BG ]]; then
"$@" | tee -a $LOG
else
"$@" &
fi
# Check if command failed and update $STEP_OK if so.
local EXIT_CODE=$?
if [[ $EXIT_CODE -ne 0 ]]; then
STEP_OK=$EXIT_CODE
[[ -w /tmp ]] && echo $STEP_OK > /tmp/step.$$
if [[ -n $LOG_STEPS ]]; then
local FILE=$(readlink -m "${BASH_SOURCE[1]}")
local LINE=${BASH_LINENO[0]}
echo "$FILE: line $LINE: Command \'$*\' failed with exit code $EXIT_CODE." >> "$LOG_STEPS"
fi
fi
return $EXIT_CODE
}
next() {
[[ -f /tmp/step.$$ ]] && { STEP_OK=$(< /tmp/step.$$); rm -f /tmp/step.$$; }
[[ $STEP_OK -eq 0 ]] && echo_success || echo_failure
echo
return $STEP_OK
}
setpass() {
echo -n "$@"
STEP_OK=0
[[ -w /tmp ]] && echo $STEP_OK > /tmp/step.$$
}
setfail() {
echo -n "$@"
STEP_OK=1
[[ -w /tmp ]] && echo $STEP_OK > /tmp/step.$$
}
#Step 3-Stop the Nodecontroller (TODO- Update this to graceful shutdown)
#step "Stoping nodecontroller service"
echo "STEP - Stopping nodecontroller">>$LOG
if [[ -x "./gracefulShutdown.sh" ]]
then
echo "File '$file' is executable" >> $LOG
./gracefulShutdown.sh | tee -a $LOG
else
echo "File '$file' is not executable or found" >> $LOG
service nodecontroller stop | tee -a $LOG
fi
#Step 4-check the number of files in the cache
step "Checking the number of files in cache\n"
FILECOUNT="$(echo `ls -l /var/cache/xms/http/xmserver/ |wc -l`)"
#TODO check to make sure there are a large number of files
setpass;
next
echo -e " $FILECOUNT files found in the xms http cache \n" | tee -a $LOG
#Step 5- Note the permisions and owner of the xmserver
#TODO should ceck to see if we have ability to make write a new folder
step "Checking File permissions on current cache directory"
try ls -al /var/cache/xms/http | grep xmserver >> $LOG
next
#Step 6- Move the Current folder to a new name
step "Renaming current directory"
try mv /var/cache/xms/http/xmserver /var/cache/xms/http/xmserver_del
next
#Step 7- Make a new directory (TODO- Need to check the file permisions
step "Making new cache directory"
try mkdir /var/cache/xms/http/xmserver
next
#Step 7a - Resetting file permisions
step "Setting chown on new cache folder"
try chown --reference=/var/cache/xms/http/xmserver_del /var/cache/xms/http/xmserver
next
#Step 7b - Resetting file permisions
step "Setting chmod on new cache folder"
try chmod --reference=/var/cache/xms/http/xmserver_del /var/cache/xms/http/xmserver
next
#Step 7c - Cehcking permissions and owner of new dir
step "Checking File permissions on current cache directory"
try ls -al /var/cache/xms/http | grep xmserver >> $LOG
next
#TODO should check to make sure that it is set correctly
#NOTE: If this is taking too long, likely you can comment this line out and uncomment one after restart
#Step - Delete the old del dir
step "\nDeleting files (This may take some time)"
start=$(date +%s.%N);
try find /var/cache/xms/http/xmserver_del -type f -delete
try rm -rf /var/cache/xms/http/xmserver_del
dur=$(echo "$(date +%s.%N) - $start" | bc)
next
printf " Complete Execution time: %.3f seconds\n" $dur | tee -a $LOG
#Step 9- Restart the Nodecontroller
#step "Restarting XMS"
#TODO Should check to see if this should be done before or after the delet happens
echo "STEP - Starting nodecontroller">>$LOG
service nodecontroller start | tee -a $LOG
#Step 10- Check the cache
step "Re-Checking current httpclient cache"
VALUE="$(curl -s http://127.0.0.1:10080/httpclient | grep cache)"
#TODO check if it is set correct
setpass;
next
echo -e "\n Current Value = {$VALUE}" |tee -a $LOG
#Step 11- Delete the old del dir
#step "\nDeleting files (This may take some time)"
#try find /var/cache/xms/http/xmserver_del -type f -delete
#try rm -rf /var/cache/xms/http/xmserver_del
#next
echo -e "\n\nProcessing Complete, see $LOG for details\n\n"