-
Notifications
You must be signed in to change notification settings - Fork 29
/
cron-box
executable file
·94 lines (78 loc) · 1.67 KB
/
cron-box
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
#!/bin/sh
# $Id$
# Run the cron for a box
FAIL_LOGFILE=/var/log/php-cron-box.fail
LOGFILE=/var/log/php-cron-box.log
exec >> $LOGFILE
exec 2>&1
exec </dev/null
now() {
date +%Y.%m.%d-%H.%M.%S
}
log_fail() {
SVC=$1
ERR=$2
echo "`now` job=$SVC exit-code=$ERR" >> $FAIL_LOGFILE
}
# pull in details for this box
. /local/systems/boxen/`hostname`
usage()
{
echo "cron-box (monthly|weekly|daily|hourly|minutely|startup)"
}
cd /local/systems
PATH="/local/systems:/usr/local/bin:$PATH"
case "$1" in
monthly)
WHAT=$MONTHLY
date=`date +"%Y%m%d-month%m"`
;;
weekly)
WHAT=$WEEKLY
date=`date +"%Y%m%d-week%V"`
;;
daily)
WHAT=$DAILY
date=`date +"%Y%m%d"`
WHAT="$WHAT check-fails"
;;
hourly)
WHAT=$HOURLY
date=`date +"%Y%m%d-%H:00"`
;;
minutely)
WHAT=$MINUTELY
date=`date +"%Y%m%d-%H:%M"`
;;
startup)
WHAT=$BOOT
date=`date +"%Y%m%d"`
;;
*)
usage
exit 1
;;
esac
# export the date for backup scripts
how=$1
export how
export date
for svc in $WHAT ; do
# Alert systems@php.net if there's a possible zombie process here. <danbrown>
if test -x /tmp/.$svc.runone.pid; then
echo "I tried to run the $1 process on $svc, but found that /tmp/.$svc.runone.pid exists." \
| mail -s "Possible Zombie Process on `hostname`" systems@php.net -- -fnoreply@php.net;
fi;
if test -x /local/systems/$svc ; then
echo
echo "`now` running $svc"
runone /tmp/.$svc.runone.pid /local/systems/$svc
ERR=$?
if test "$ERR" != "0"; then
log_fail $svc $ERR
fi
else
echo "Something is wrong. /local/systems/$svc on `hostname` is not executable." \
| mail -s "Broken cronjob on `hostname`" systems@php.net -- -fnoreply@php.net
fi
done