Skip to content

Commit

Permalink
Release 1.3.1
Browse files Browse the repository at this point in the history
* Updated donation section.
* (cron-shim)Updated cron-shim.sh to 1.2.1 added time in human readable
* (cron-shim)Added log pruning to keep log files below 10MB
  • Loading branch information
jordantrizz committed Nov 4, 2024
1 parent c056640 commit aa31e08
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 36 deletions.
44 changes: 20 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,32 @@
Table of Contents
=================

* [Table of Contents](#table-of-contents)
* [wp-shelltools](#wp-shelltools)
* [Rename from gp-tools to wp-shelltools](#rename-from-gp-tools-to-wp-shelltools)
* [Donate](#donate)
* [Install](#install)
* [Requirements](#requirements)
* [Help](#help)
* [Help Command](#help-command)
* [Advanced Documentation](#advanced-documentation)
* [<a href="docs/gp-goaccess.md">gp-goaccess</a>](#gp-goaccess)
* [<a href="docs/gp-api.md">gp-api</a>](#gp-api)
* [<a href="docs/gp-plugins.md">gp-plugins</a>](#gp-plugins)
* [<a href="docs/attackscan.md">attackscan.sh</a>](#attackscansh)
* [Debugging](#debugging)
* [Future Features](#future-features)
* [Donate](#donate-1)
* [Resources](#resources)
- [Table of Contents](#table-of-contents)
- [Donate](#donate)
- [wp-shelltools](#wp-shelltools)
- [Install](#install)
- [Requirements](#requirements)
- [Help](#help)
- [Directories](#directories)
- [Advanced Documentation](#advanced-documentation)
- [Debugging](#debugging)
- [Future Features](#future-features)
- [ToDo](#todo)
- [Resources](#resources)
<!--te-->

# Donate
If you like any of the scripts or tools, please consider donating to help support the development of these tools.

[![Buy Me A Coffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://ko-fi.com/jordantrask)
[![ManagingWP](https://i.imgur.com/x5SjITX.png)](https://managingwp.io/sponsor)


# wp-shelltools
The goal of this project is to make it easy to manage and maintain WordPress servers using shell scripting. This repository was original named gp-tools, but decided to make it provider agnostic

You might find that there are still tools and functions that have gridpane or gp in their name. This will change when it becomes a priority.

# Donate
[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://wpinfo.net/sponsor/)

# Install
## Requirements
* You need root, otherwise this makes no sense.
Expand Down Expand Up @@ -94,11 +93,8 @@ Add a .debug file to any directory to get debug information.
* Place some scripts into functions or separate files not inside root for a cleaner directory structure and code management.
* goaccess: Add filtering for 403 forbidden as they're blocked and not resource intensive

# Donate
[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://managingwp.io/sponsor/)

# Resources
* [Managing WP](https://mangingwp.io) - WordPress Articles and more!
* [Managing WordPress](https://www.facebook.com/groups/managingwordpress) - Created and managed by me.
* [Managing WordPress Discord](https://discord.gg/QCsHM234zh) - Come and chat about WordPress
* [GridPane Facebook Group](https://www.facebook.com/groups/selfmanagedwordpress) - Managed by GridPane and full of customers and WordPress community members.
* [Managing WordPress Discord](https://discord.gg/QCsHM234zh) - Come and chat about WordPress
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.0
1.3.1
10 changes: 10 additions & 0 deletions cron-shim/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Donate
If you like any of the scripts or tools, please consider donating to help support the development of these tools.

[![Buy Me A Coffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://ko-fi.com/jordantrask)
[![ManagingWP](https://i.imgur.com/x5SjITX.png)](https://managingwp.io/sponsor)

# cron-shim.sh
A shim between linux cron and WordPress.

Expand Down Expand Up @@ -33,6 +39,10 @@ LOG_FILE="cron-shim.log" # Location for WordPress cron log file if LOG_TO_FILE="
```

# Changelog
## 1.2.1
* Added human readable time to log output at end of run.
* Added log pruning to keep log files below 10MB

## 1.2.0
* Implemented multisite detection and running of cron for all sites.
* Implemented queue for running cronjobs to support multisite.
Expand Down
3 changes: 0 additions & 3 deletions cron-shim/cron-shim-report.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/bin/bash
# -- Created by Jordan - hello@managingwp.io - https://managingwp.io
# -- Last Updated: 2023-12-06

# -- Ger version from VERSION
VERSION="1.0.5"
SCRIPT_NAME="cron-shim"

Expand Down
40 changes: 32 additions & 8 deletions cron-shim/cron-shim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# Example: */5 * * * * /home/systemuser/cron-shim.sh

# -- Variables
VERSION="1.2.0"
VERSION="1.2.1"
PID_FILE="/tmp/cron-shim.pid"
SCRIPT_NAME=$(basename "$0") # - Name of this script
declare -A SITE_MAP # - Map of sites to run cron on
Expand Down Expand Up @@ -64,28 +64,46 @@ function _time_spent () {
# -- prune_old_logs
function prune_old_logs () {
# -- Prune old logs
_log "Starting log pruning"
if [[ $LOG_TO_FILE == "1" ]]; then
# -- Prune logs larger than 10MB
if [[ $(stat -c %s $LOG_FILE) -gt 10485760 ]]; then
_log "Pruning $LOG_FILE"

mv $LOG_FILE.tmp $LOG_FILE
if [[ $(stat -c %s "$LOG_FILE") -gt 10485760 ]]; then
_log "-- Pruning $LOG_FILE"
truncate -s 1M "$LOG_FILE"
_log "-- Log file $LOG_FILE pruned"
else
_log "-- Log file $LOG_FILE is less than 10MB"
fi
else
_log "-- Log file logging is disabled"
fi
}

function seconds_to_human_readable (){
local SECONDS HOURS MINUTES SECS
local SECONDS_ARG=$1
SECONDS=$(printf "%.0f" $SECONDS_ARG) # Round the input to the nearest integer
HOURS=$((SECONDS/3600%24))
MINUTES=$((SECONDS/60%60))
SECS=$((SECONDS%60))
printf "%02dh %02dm %02ds\n" $DAYS $HOURS $MINUTES $SECS
}

# -----------------------------------------------
# -- Checks
# -----------------------------------------------

# Log the start time
START_TIME=$(date +%s.%N)



# Log header
_log "==================================================================================================="
_log "== Cron Shim ${VERSION} - job start $(echo $START_TIME|date +"%Y-%m-%d_%H:%M:%S")"
_log "==================================================================================================="


# -- Check if cron-shim.conf exists and source it
if [[ -f $SCRIPT_DIR/cron-shim.conf ]]; then
_log "Found and sourcing $SCRIPT_DIR/cron-shim.conf"
Expand All @@ -97,6 +115,9 @@ fi
# Check if $LOG_TO_FILE is enabled and set the log file location
[[ $LOG_TO_FILE == "1" ]] && _log "Logging to $LOG_FILE"

# Prune old logs
prune_old_logs

# -- Starting
_log "Starting $SCRIPT_NAME $VERSION in $SCRIPT_DIR on $(hostname)"

Expand Down Expand Up @@ -197,7 +218,6 @@ _log "==========================================================================
_log ""

# Gather cron run data.
JOB_RUN_SITES=()
JOB_RUN_SITES_TIME=()
JOB_RUN=""
JOB_RUN_COUNT=0
Expand All @@ -206,6 +226,7 @@ CRON_ERROR_COUNT=0
CRON_TIMEOUT_COUNT=0
SITE_ID=""
MULTISITE_SITES=""
COUNTER=0

_log "==================================================================================================="
_log "- Starting queue run for $DOMAIN_NAME"
Expand All @@ -232,9 +253,11 @@ _log ""
_log "==================================================================================================="
_log "Cron queue type:$JOB_RUN count: $JOB_RUN_COUNT"
_log "==================================================================================================="

for SITE in "${!SITE_MAP[@]}"; do
COUNTER=$((COUNTER + 1))
_log "==================================================================================================="
_log "- Running cron job for $DOMAIN_NAME - $SITE ${SITE_MAP[$site]}"
_log "- Running cron job $COUNTER/$JOB_RUN_COUNT for $DOMAIN_NAME - $SITE ${SITE_MAP[$site]}"
_log "==================================================================================================="
if [[ $JOB_RUN == "multi" ]]; then
CRON_CMD="$WP_CLI --path=$WP_ROOT --url=$SITE $CRON_CMD_SETTINGS"
Expand Down Expand Up @@ -337,6 +360,7 @@ _log "==========================================================================

_log ""
_log "===================================================================================================
== Cron run completed in $TIME_SPENT seconds with $CPU_USAGE% CPU usage.
== Cron run completed in $TIME_SPENT seconds / $(seconds_to_human_readable "$TIME_SPENT") / with $CPU_USAGE% CPU usage.
== Cron Errors: $CRON_ERROR_COUNT Cron Timeouts: $CRON_TIMEOUT_COUNT
== Cron run End Time - $(echo $END_TIME | date +"%Y-%m-%d_%H:%M:%S")
==================================================================================================="

0 comments on commit aa31e08

Please sign in to comment.