-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathservice_crond.sh
More file actions
executable file
·377 lines (318 loc) · 15.2 KB
/
service_crond.sh
File metadata and controls
executable file
·377 lines (318 loc) · 15.2 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
#!/bin/sh
##########################################################################
# If not stated otherwise in this file or this component's Licenses.txt
# file the following copyright and licenses apply:
#
# Copyright 2015 RDK Management
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##########################################################################
#######################################################################
# Copyright [2014] [Cisco Systems, Inc.]
#
# Licensed under the Apache License, Version 2.0 (the \"License\");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an \"AS IS\" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#######################################################################
# ----------------------------------------------------------------------------
# This script prepares cron files and brings up a crond
# The prepared configuration files will have the cron daemon
# execute all files in a well-known directory at predictables times.
#
# Also this script creates a script to be run by the cron daemon on
# a daily basis. The purpose of that script will be to trigger the
# ddns-start event
# ----------------------------------------------------------------------------
source /etc/utopia/service.d/ulog_functions.sh
source /etc/utopia/service.d/log_capture_path.sh
if [ -f /lib/rdk/utils.sh ];then
. /lib/rdk/utils.sh
fi
source /etc/device.properties
SERVICE_NAME="crond"
SELF_NAME="`basename "$0"`"
ntpHealthCheck=`sysevent get NTPHealthCheckSupport`
service_start ()
{
echo_t "SERVICE_CROND : starting ${SERVICE_NAME} service"
ulog ${SERVICE_NAME} status "starting ${SERVICE_NAME} service"
killall crond
CRONTAB_DIR="/var/spool/cron/crontabs/"
CRONTAB_FILE=$CRONTAB_DIR"root"
if [ ! -e $CRONTAB_FILE ] || [ ! -e "/etc/cron/cron.monthly" ] ; then
echo_t "SERVICE_CROND : creating cron files"
# make a pseudo random seed from our mac address
# we will get the same values of random over reboots
# but there will be divergence of values accross hosts
# which is the property we are looking for
if [ "$WAN0_IS_DUMMY" = "true" ]; then
INT="privbr"
else
INT="wan0"
fi
OUR_MAC=`ip link show $INT | grep link | awk '{print $2}'`
MAC1=`echo "$OUR_MAC" | awk 'BEGIN { FS = ":" } ; { printf ("%d", "0x"$6) }'`
MAC2=`echo "$OUR_MAC" | awk 'BEGIN { FS = ":" } ; { printf ("%d", "0x"$5) }'`
RANDOM=`expr "$MAC1" \* "$MAC2"`
mkdir -p $CRONTAB_DIR
echo "* * * * * execute_dir /etc/cron/cron.everyminute" > $CRONTAB_FILE
echo "1,6,11,16,21,26,31,36,41,46,51,56 * * * * execute_dir /etc/cron/cron.every5minute" >> $CRONTAB_FILE
echo "2,12,22,32,42,52 * * * * execute_dir /etc/cron/cron.every10minute" >> $CRONTAB_FILE
num1=$RANDOM
rand1=`expr "$num1" % 60`
rand4=`expr "$RANDOM" \* 2`
rand4=`expr "$rand4" % 60`
echo "$rand1 * * * * execute_dir /etc/cron/cron.hourly" >> $CRONTAB_FILE
echo "$rand4 * * * * /usr/ccsp/tad/xfinity_health_test.sh" >> $CRONTAB_FILE
echo "1 */1 * * * /usr/bin/RxTx100" >> $CRONTAB_FILE
echo "10 */6 * * * /usr/ccsp/tad/getSsidNames.sh" >> $CRONTAB_FILE
#rdkb-4297 Runs on the 1st minute of every 12th hour
if [ "$MOCA_SUPPORTED" != "false" ]; then
echo "1 */12 * * * /usr/ccsp/pam/moca_status.sh" >> $CRONTAB_FILE
fi
#RDKB-17984: Runs every 12 hours and prints mesh status
if [ "$BOX_TYPE" != "XB3" ]; then
echo "1 */12 * * * /usr/ccsp/wifi/mesh_status.sh" >> $CRONTAB_FILE
fi
if [ "$BOX_TYPE" == "XB3" ]; then
echo "*/10 * * * * /rdklogger/log_ps_cpu_mem_host.sh" >> $CRONTAB_FILE
fi
#zqiu: monitor lan client traffic
echo "* * * * * /usr/ccsp/tad/rxtx_lan.sh" >> $CRONTAB_FILE
if [ "$BOX_TYPE" == "SR300" ] || [ "$BOX_TYPE" == "SR213" ] || [ "$BOX_TYPE" == "SCER11BEL" ]; then
echo "* * * * * /etc/sky/set_dscp_lan.sh" >> $CRONTAB_FILE
fi
if [ "$BOX_TYPE" == "SCXF11BFL" ]; then
echo "* * * * * /etc/comcast/set_dscp_lan.sh" >> $CRONTAB_FILE
fi
echo "1 */6 * * * /usr/ccsp/tad/log_sixhourly.sh" >> $CRONTAB_FILE
#RDKB-9367, file handle monitor, needs to be run every 12 hours
echo "1 */12 * * * /usr/ccsp/tad/FileHandle_Monitor.sh" >> $CRONTAB_FILE
if [ "$MODEL_NUM" = "DPC3941B" ] || [ "$MODEL_NUM" = "DPC3939B" ] || [ "$MODEL_NUM" = "CGA4131COM" ] || [ "$MODEL_NUM" = "CGA4332COM" ] || [ "$MODEL_NUM" = "SG417DBCT" ]; then
echo "*/15 * * * * /usr/ccsp/tad/log_staticIP_client_info.sh" >> $CRONTAB_FILE
fi
echo "1 */12 * * * /usr/ccsp/tad/log_twice_day.sh" >> $CRONTAB_FILE
#RDKB-45059 log the zebra.conf status for every 12 hours
echo "0 */12 * * * /usr/ccsp/tad/Zebra_conf_status.sh" >> $CRONTAB_FILE
if [ "$BOX_TYPE" == "WNXL11BWL" ] || [ "$BOX_TYPE" == "XB6" ] || [ "$BOX_TYPE" == "VNTXER5" ] || [ "$BOX_TYPE" == "SCER11BEL" ] || [ "$BOX_TYPE" == "SCXF11BFL" ]; then
#run idm recovery for each 10 minutes
echo "*/10 * * * * /etc/idm/idm_recovery.sh" >> $CRONTAB_FILE
fi
if [ "$BOX_TYPE" == "VNTXER5" ]; then
#run thermal monitoring script every 5 minutes
echo "*/5 * * * * /etc/get_XER5_thermal.sh" >> $CRONTAB_FILE
fi
num1=$RANDOM
num2=$RANDOM
rand1=`expr "$num1" % 60`
rand2=`expr "$num2" % 24`
echo "$rand1 $rand2 * * * execute_dir /etc/cron/cron.daily" >> $CRONTAB_FILE
num1=$RANDOM
num2=$RANDOM
num3=$RANDOM
rand1=`expr "$num1" % 60`
rand2=`expr "$num2" % 24`
rand3=`expr "$num3" % 7`
echo "$rand1 $rand2 * * $rand3 execute_dir /etc/cron/cron.weekly" >> $CRONTAB_FILE
num1=$RANDOM
num2=$RANDOM
num3=$RANDOM
rand1=`expr "$num1" % 60`
rand2=`expr "$num2" % 24`
rand3=`expr "$num3" % 28`
echo "$rand1 $rand2 $rand3 * * execute_dir /etc/cron/cron.monthly" >> $CRONTAB_FILE
# update mso potd every midnight at 00:05
echo "5 0 * * * sysevent set potd-start" >> $CRONTAB_FILE
echo "*/15 * * * * /bin/sh /usr/ccsp/tad/gui_session_expiry.sh" >> $CRONTAB_FILE
# Generate Firewall statistics hourly
# Don't Zero iptable Counter
echo "58 * * * * /usr/bin/GenFWLog -nz" >> $CRONTAB_FILE
SELFHEAL_CRON_ENABLE=$(syscfg get SelfHealCronEnable)
SELFHEAL_ENABLE=$(syscfg get selfheal_enable)
if [ "$SELFHEAL_CRON_ENABLE" = "true" ] && [ "$SELFHEAL_ENABLE" = "true" ]; then
echo_t "SelfHeal Cron is enabled"
# Monitor selfheal_aggressive.sh based on syscfg value
AGGRESSIVE_INTERVAL=$(syscfg get AggressiveInterval)
if [ -z "$AGGRESSIVE_INTERVAL" ]; then
AGGRESSIVE_INTERVAL=5
fi
#Write cron rule
echo "*/$AGGRESSIVE_INTERVAL * * * * /usr/ccsp/tad/selfheal_aggressive.sh" >> $CRONTAB_FILE
# Monitor resource_monitor.sh based on syscfg value
RESOURCE_MONITOR_INTERVAL=$(syscfg get resource_monitor_interval)
if [ -z "$RESOURCE_MONITOR_INTERVAL" ]; then
RESOURCE_MONITOR_INTERVAL=15
fi
echo "*/$RESOURCE_MONITOR_INTERVAL * * * * /usr/ccsp/tad/resource_monitor.sh" >> $CRONTAB_FILE
# Monitor self_heal_connectivity_test.sh based on syscfg value
SELFHEAL_PING_INTERVAL=$(syscfg get ConnTest_PingInterval)
if [ -z "$SELFHEAL_PING_INTERVAL" ]; then
SELFHEAL_PING_INTERVAL=60
fi
echo "*/$SELFHEAL_PING_INTERVAL * * * * /usr/ccsp/tad/self_heal_connectivity_test.sh" >> $CRONTAB_FILE
echo_t "Selfheal cron jobs are started"
else
echo_t "Selfheal cron is disabled"
# Monitor syscfg DB every 15minutes
echo "*/15 * * * * /usr/ccsp/tad/syscfg_recover.sh" >> $CRONTAB_FILE
# Monitor resource_monitor.sh every 5 minutes TCCBR-3288
# if [ "$BOX_TYPE" = "TCCBR" ]; then
echo "*/5 * * * * /usr/ccsp/tad/resource_monitor_recover.sh" >> $CRONTAB_FILE
# fi
fi
# RDKB-23651
if [ "$THERMALCTRL_ENABLE" = "true" ]; then
echo "*/15 * * * * /usr/ccsp/tad/check_fan.sh" >> $CRONTAB_FILE
fi
if [ "$BOX_TYPE" == "HUB4" ] || [ "$BOX_TYPE" == "SR300" ] || [ "$BOX_TYPE" == "SE501" ] || [ "$BOX_TYPE" == "SR213" ] || [ "$BOX_TYPE" == "WNXL11BWL" ]; then
# add syncing the timeoffset everyday at 01:00 AM
echo "0 1 * * * /etc/sky/sync_timeoffset.sh" >> $CRONTAB_FILE
#To monitor all wifi interface packets in every 15minutes
echo "*/15 * * * * /etc/sky/monitor_wifi_packets.sh" >> $CRONTAB_FILE
#To monitor /tmp directory every 10 minutes
echo "*/10 * * * * /etc/sky/monitor_tmp.sh" >> $CRONTAB_FILE
#To monitor all wifi interface dhd dump in every 1hour
addCron "48 * * * * sh /etc/sky/monitor_dhd_dump.sh &"
fi
if [ "$BOX_TYPE" != "SR300" ] && [ "$BOX_TYPE" != "SE501" ] && [ "$BOX_TYPE" != "WNXL11BWL" ] && [ "$BOX_TYPE" != "SCER11BEL" ] && [ "$BOX_TYPE" != "SCXF11BFL" ]; then
#RDKB-43895 log the firmware bank informations in selfheal log
echo "5 */12 * * * /usr/bin/FwBankInfo" >> $CRONTAB_FILE
fi
if [ "$BOX_TYPE" == "HUB4" ]; then
addCron "51 * * * * sh /etc/utopia/service.d/handle_log_monitor_pause.sh &"
#To monitor endpoint failure every 15 minutes
echo "*/15 3-4 * * * /etc/sky/monitor_voice_endpoint.sh" >> $CRONTAB_FILE
fi
if [ "$BOX_TYPE" == "HUB4" ] || [ "$BOX_TYPE" == "SR213" ] || [ "$ntpHealthCheck" == "true" ]; then
#To monitor ntp sync failure every 2 hrs
if [ -e "/etc/sky/ntp_health_check.sh" ]; then
echo "1 */2 * * * /etc/sky/ntp_health_check.sh" >> $CRONTAB_FILE
fi
fi
if [ "$BOX_TYPE" == "SCER11BEL" ] && [ "$ntpHealthCheck" == "true" ]; then
# Add syncing the timeoffset everyday at 01:00 AM
echo "0 1 * * * /etc/sky/sync_timeoffset.sh" >> $CRONTAB_FILE
fi
# Logging current chain mask value of 2G - runs on 1st minute of every 12th hour - only for 3941 box
if [ -n "$(echo "$MODEL_NUM" | grep 3941)" ]; then
echo "1 */12 * * * rpcclient 169.254.101.2 \"/etc/ath/CurrentChainMask_Logging.sh\"" >> $CRONTAB_FILE
fi
# Add Unique Telemetry ID if enabled
telemtery_enable=`syscfg get unique_telemetry_enable`
telemtery_time_interval=`syscfg get unique_telemetry_interval`
telemtery_tag=`syscfg get unique_telemetry_tag`
if [ "$telemtery_enable" = "true" ] && [ 0"$telemtery_time_interval" -gt 0 ] && [ ! -z "$telemtery_tag" -a "$telemtery_tag" != " " ] ; then
#Convert time interval(in minutes) to days, hours and minutes
d=$(($telemtery_time_interval / (60*24)))
h=$((($telemtery_time_interval % (60*24)) / 60))
m=$((($telemtery_time_interval % (60*24)) % 60))
if [ $d -gt 0 ] ; then
day="*/$d"
hour="$h"
mins="$m"
elif [ $h -gt 0 ] ; then
day="*"
hour="*/$h"
mins="$m"
else
day="*"
hour="*"
mins="*/$m"
fi
echo "$mins $hour $day * * /usr/ccsp/pam/unique_telemetry_id.sh" >> $CRONTAB_FILE
fi
# monitor syslog every 5 minute
# echo "#! /bin/sh" > /etc/cron/cron.every5minute/log_every5minute.sh
# echo "/usr/sbin/log_handle.sh" >> /etc/cron/cron.every5minute/log_every5minute.sh
# chmod 700 /etc/cron/cron.every5minute/log_every5minute.sh
#monitor start-misc in case wan is not online
addCron "* * * * * /etc/utopia/service.d/misc_handler.sh"
addCron "* * * * * /usr/ccsp/tad/selfheal_bootup.sh"
#monitor cosa_start_rem triggered state in case its not triggered on
#bootup even after 10 minutes then we have to trigger this via cron
addCron "2,12,22,32,42,52 * * * * /usr/ccsp/tad/selfheal_cosa_start_rem.sh"
# Adding RemotePortUsage script if it is enabled
REMOTE_PORT_USAGE=`syscfg get TrackRemotePortUsage`
if [ "$REMOTE_PORT_USAGE" != "NULL" ]; then
interval=$(echo "$REMOTE_PORT_USAGE" | cut -d';' -f1)
echo "*/$interval * * * * /usr/ccsp/tad/remote_port_usage.sh" >> $CRONTAB_FILE
fi
#This variable is to check RFC WANLinkHeal Enabled/Disabled from syscfg DB
rfc_wanlinkheal_status=""
rfc_wanlinkheal_status=`syscfg get wanlinkheal`
#To invoke start_gw_health script on bootup-check, Follwing condition need to statisfy
#RFC ETHWAN should be false/null and WAN_TYPE should be DOCSIS
#RF WANLinkHeal should be true and BOX_TYPE should be plaftorm specfic
#In CISCOXB3 platform, does not have WAN_TYPE paramenter in /etc/device.properties file, So added MODEL_NUM Check along with WAN_TYPE.
if [ "$WAN_TYPE" = "DOCSIS" ] || [ "$MODEL_NUM" = "DPC3941" ] || [ "$MODEL_NUM" = "DPC3941B" ] || [ "$MODEL_NUM" = "DPC3939B" ]; then
if [ "$rfc_wanlinkheal_status" = "true" ]; then
if [ "$BOX_TYPE" = "XB3" ] || [ "$BOX_TYPE" = "XB6" ] || [ "$BOX_TYPE" = "TCCBR" ]; then
echo_t "RFC WANLinkHeal Feature is Enabled"
addCron "2,12,22,32,42,52 * * * * /usr/ccsp/tad/start_gw_heath.sh"
else
echo_t "RFC WANLinkHeal Feature is not Enabled"
fi
else
echo_t "Set RFC WANLinkHeal flag to Enable for WANLinkHeal Feature support"
fi
else
echo_t "This Device WAN TYPE is not DOCSIS, Needed DOCSIS type Device for WANLinkHeal"
fi
fi
# start the cron daemon
# echo "[utopia][registration] Starting cron daemon"
echo_t "SERVICE_CROND : Starting cron daemon"
crond -l 9
sysevent set ${SERVICE_NAME}-status "started"
}
service_stop ()
{
echo_t "SERVICE_CROND : stopping ${SERVICE_NAME} service"
ulog ${SERVICE_NAME} status "stopping ${SERVICE_NAME} service"
killall crond
sysevent set ${SERVICE_NAME}-status "stopped"
}
# Entry
echo_t "SERVICE_CROND : event $1"
case "$1" in
"${SERVICE_NAME}-start")
service_start
;;
"${SERVICE_NAME}-stop")
service_stop
;;
"${SERVICE_NAME}-restart")
service_stop
service_start
;;
ntpclient-status)
STATUS=`sysevent get ntpclient-status`
if [ "started" = "$STATUS" ] ; then
ulog ${SERVICE_NAME} status "restarting ${SERVICE_NAME} service"
killall crond
crond -l 9
fi
;;
*)
echo "Usage: $SELF_NAME [${SERVICE_NAME}-start | ${SERVICE_NAME}-stop | ${SERVICE_NAME}-restart]" >&2
exit 3
;;
esac