2021-04-07 09:43:20 -07:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# wordpress-tools
|
|
|
|
# https://git.stack-source.com/msb/wordpress-tools
|
2022-08-22 14:01:24 -07:00
|
|
|
# Copyright (c) 2022 Matthew Saunders Brown <matthewsaundersbrown@gmail.com>\
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
2021-04-07 09:43:20 -07:00
|
|
|
|
|
|
|
# must be root, will su to vhost users for wp cron runs
|
|
|
|
if [ "$USER" != "root" ]; then
|
|
|
|
exec sudo $0
|
|
|
|
fi
|
|
|
|
|
2023-09-11 15:38:41 -07:00
|
|
|
# create virtualhostArray listing all virtualhost on the server
|
2021-04-07 09:43:20 -07:00
|
|
|
cd /srv/www
|
|
|
|
virtualhostArray=(`ls -1|grep -v ^html$`)
|
|
|
|
|
2023-09-26 10:25:30 -07:00
|
|
|
# create empty virtualhostExclusionArray array (any domains added to this array will be skipped)
|
|
|
|
declare -a virtualhostExclusionArray
|
|
|
|
|
2023-09-11 15:38:41 -07:00
|
|
|
# check for local config, which can be used to override either of the above arrays
|
|
|
|
if [[ -f /usr/local/etc/wp-cron.conf ]]; then
|
|
|
|
source /usr/local/etc/wp-cron.conf
|
|
|
|
# conf file could contain either one or both arrays, configured like this:
|
|
|
|
#virtualhostArray=("example.com" "example.net")
|
|
|
|
#virtualhostExclusionArray=("example.org")
|
|
|
|
fi
|
|
|
|
|
2021-04-07 09:43:20 -07:00
|
|
|
for VHOST in "${virtualhostArray[@]}"
|
|
|
|
do
|
|
|
|
# check if VHOST has been added to exclustion array
|
|
|
|
if [[ ! " ${virtualhostExclusionArray[@]} " =~ " ${VHOST} " ]]; then
|
|
|
|
# basic check for WP install
|
|
|
|
if [ -f /srv/www/$VHOST/html/wp-config.php ]; then
|
|
|
|
VHOST_USER=$(stat -c '%U' /srv/www/$VHOST)
|
|
|
|
# confirm that WP really is installed
|
2023-09-26 10:25:30 -07:00
|
|
|
if $(timeout 5 su -c "wp core is-installed --path=/srv/www/$VHOST/html/" $VHOST_USER); then
|
2021-04-07 09:43:20 -07:00
|
|
|
# run cron for VHOST as VHOST_USER
|
|
|
|
/usr/bin/logger --tag wp-cron "running wp-cli cron for $VHOST as $VHOST_USER"
|
|
|
|
su -c "/usr/local/bin/wp cron event run --due-now --quiet --path=/srv/www/$VHOST/html/" $VHOST_USER
|
2023-09-26 10:25:30 -07:00
|
|
|
else
|
|
|
|
echo "NOTICE: 'wp core is-installed' failed for $VHOST (user $VHOST_USER)" | mail -s "wp-cron" webmaster -aFrom:webmaster
|
2021-04-07 09:43:20 -07:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|