-
Notifications
You must be signed in to change notification settings - Fork 67
/
rebuild-cache
executable file
·40 lines (31 loc) · 1.05 KB
/
rebuild-cache
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
#!/bin/bash
usage(){
echo -n
fmt <<EOF
DESCRIPTION
Rebuild one of the caches stored in APCu for the standardebooks.org FPM pool.
USAGE
rebuild-cache {bulk-downloads,feeds}
EOF
exit 1
}
if [ $# -eq 1 ]; then
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
usage
fi
fi
if [ $# -ne 1 ]; then
usage
fi
# If this script is run by a user without sudo powers, they can be given permission to run this command by creating a file in `sudoers.d` with:
#
# MY_USERNAME ALL=(www-data) NOPASSWD: /usr/bin/env SCRIPT_FILENAME=/tmp/rebuild-cache.php REQUEST_METHOD=GET cgi-fcgi -bind -connect *
type="$1"
if [ "${type}" = "bulk-downloads" ]; then
echo "<?php require_once('Core.php'); Library::RebuildBulkDownloadsCache(); ?>" > /tmp/rebuild-cache.php
fi
if [ "${type}" = "feeds" ]; then
echo "<?php require_once('Core.php'); Feed::RebuildFeedsCache(); ?>" > /tmp/rebuild-cache.php
fi
sudo --user=www-data env SCRIPT_FILENAME=/tmp/rebuild-cache.php REQUEST_METHOD=GET cgi-fcgi -bind -connect "/run/php/standardebooks.org.sock" &> /dev/null
rm /tmp/rebuild-cache.php