-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcron.sh
executable file
·108 lines (93 loc) · 2.19 KB
/
cron.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
#!/usr/bin/env bash
BASE_DIR=""
PHP=""
OWNER=""
CLEAR_STORAGE=0
CLEAR_CACHE=0
RUN_QUEUE=0
usage() {
printf "Usage: $0 [OPTS] -d SITE_DIR\n" 1>&2
printf "Options:\n" 1>&2
printf "\t-d SITE_DIR\tpath to CMS base directory\n" 1>&2
printf "\t-p PHP_BIN\tpath to PHP executable\n" 1>&2
printf "\t-o OWNER\tuser:group for writeable cms directories\n" 1>&2
printf "\t-s\t\tclear storage\n" 1>&2
printf "\t-c\t\tclear cache\n" 1>&2
printf "\t-q\t\trun the queue\n" 1>&2
}
exit_abnormal() {
usage
exit 1
}
print_opts() {
echo "BASE_DIR: ${BASE_DIR}"
# echo "PHP_VERSION: ${PHP_VERSION}"
echo "PHP: ${PHP}"
${PHP} -v
echo "Clear Storage|Cache: ${CLEAR_STORAGE}|${CLEAR_CACHE}"
echo "Owner: $OWNER"
}
while getopts ":d:p:o:hsqc" options; do
case "${options}" in
d)
BASE_DIR=${OPTARG}
;;
p)
PHP=${OPTARG}
;;
o)
OWNER=${OPTARG}
;;
h)
usage
exit 0
;;
s)
CLEAR_STORAGE=1
;;
c)
CLEAR_CACHE=1
;;
q)
RUN_QUEUE=1
;;
:)
echo "Error: -${OPTARG} requires an argument"
exit_abnormal
;;
esac
done
current_time=$(date +"%Y-%m-%d %H:%M:%S")
printf "\n============= Starting cleanup.sh [%s] =============\n" "$current_time"
if [ -z $BASE_DIR ]; then
echo "Error: -d flag is required" >2
exit_abnormal
fi
if [ -z $PHP ]; then
PHP=$(which php)
fi
set -eux;
# Set permissions
if [ ! -z $OWNER ]; then
sudo chown -R "${OWNER}" "${BASE_DIR}"
sudo chmod a+w -R "${BASE_DIR}/storage"
fi
# Clear storage
if [ $CLEAR_STORAGE -eq 1 ]; then
cd "${BASE_DIR}"
sudo rm -rf storage/runtime/* || true
mkdir -p storage/runtime
sudo chmod -R 775 storage/runtime
sudo rm -rf storage/logs/*.[0-9]* || true
fi
# Clear caches
if [ $CLEAR_CACHE -eq 1 ]; then
cd "${BASE_DIR}"
$PHP craft clear-caches/all
fi
# Run the queue
if [ $RUN_QUEUE -eq 1 ]; then
echo "Running queue"
cd "${BASE_DIR}"; $PHP craft queue/run &
fi
printf "\n============= Complete =============\n"