Skip to content

Commit

Permalink
Release 2.8.8
Browse files Browse the repository at this point in the history
feat(git): grr function to reset branch to remote origin
8732dbb feat(git): grr function to reset branch to remote origin
a63795e fix(cpu): Added success color to cpu command
705eaed fix(zshbop): Changed file version to VERSION but didn't updated zshbop.zsh
c05844e fix(sysinfo): Fixed sysinfo, mem and cpu and added to motd
3fa0b1c fix(mem): The command mem wasn't reporting total.
c3a4433 style(mem): Fixed style on mem command
40955d3 refactor(zshbop): Created include.zsh for including the zshbop framework
6a24b5c feat(worpdress): Added wp-profile command to install wp-cli/profile-command
eb668cd feat(software): Check if ncdu is installed, if not create function to install it
b1e72e1 feat(software): Added php-relay to software command
4504f49 docs(php-relay): Created KB for php-relay and added litespeed install instructions
6f42686 enhance(php-relay): Addd more to php-relay.md KB
7727777 revert(gridpane): Removed gp-duplicacy-audit
a139097 feat(softare): Software installation for latest goaccess
65ecc54 feat(scripts): Added script cron.sh for running crons
c01a72d feat(git): Created git-squash-commits to git commit history
cedec5b fix(git-squash-commit): Git log commands were all on one line, now properly formatted
b3a6326 feat(scripts): Created cron.sh script for running cron
4ba5dc6 enhance(cronsh): Updated cron.sh with additional improvements
6c3d9d4 enhance(cronsh): Print out that heartbeat was sent and the URL
bd698e0 fix(git-check): Logic in git-check-exit to be able to return to zsh shell
  • Loading branch information
jordantrizz committed Jun 1, 2023
1 parent 5c20fca commit a4ff017
Show file tree
Hide file tree
Showing 12 changed files with 487 additions and 192 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.8.7
2.8.8
28 changes: 26 additions & 2 deletions cmds/cmds-git.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,18 @@ function gpa {
git apply $1
}

# -- grr - Git reset remote
help_git[grr]="Git reset remote"
function grr {
if [[ $# -ne 1 ]]; then
echo "Usage: git-reset-remote branch"
return 1
fi

_loading "Resetting remote branch $1"
git reset --hard origin/$1
}

# -- gl - Git log
help_git[gl]="Git log"
function gl {
Expand Down Expand Up @@ -280,7 +292,19 @@ function git-check-exit () {
[[ ! -d $GIT_HOME ]] && return 0
git-check-repos $GIT_HOME
if [[ $? -ne 0 ]]; then
echo -n "Uncommited and unpushed changes found. Press enter to continue anyway. "
echo -n "Uncommited and unpushed changes found. Press enter to continue anyway or 'r' to return to ZSH\n"
read response
if [[ $response != "" ]]; then
zsh
else
exit 1
fi
fi
}
}

# -- git-squash-commits
help_git[git-squash-commits]="Squash commits"
function git-squash-commits () {
GIT_LOG="$(git log --oneline)"
git reset $(git commit-tree HEAD^{tree} -m "$GIT_LOG")
}
9 changes: 0 additions & 9 deletions cmds/cmds-gridpane.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,6 @@ gp-mysqlpass () {
grep -oP '^mysql-root:\K.*' /root/gridenv/promethean.env | openssl enc -d -a -salt
}

# -- gp-duplicacy-audit
help_gridpane[gp-duplicacy-audit]="Audit Duplicacy backups"
gp-duplicacy-audit () {
local duplicacy_repository=$(find /var/www -name ".duplicacy" | head -n 1)
echo "Found at ${duplicacy_repository}"
cd ${duplicacy_repository}
duplicacy check -tabular | grep 'all' | awk {' print $1 " "$10 '} | sed 's/gridpane-[[:alnum:]]*-[[:alnum:]]*-[[:alnum:]]*-[[:alnum:]]*-[[:alnum:]]*-//' | column -t
}

# gp-logs
help_gridpane[gp-logs]="Tail GridPane Logs"
gp-logs () {
Expand Down
45 changes: 44 additions & 1 deletion cmds/cmds-software.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -400,4 +400,47 @@ if [[ $? == "1" ]]; then
_zshbop_bin
fi
}
fi
fi

# -- ncdu
help_software[ncdu]="Install ncdu"
_cexists ncdu
if [[ $? == "1" ]]; then
function ncdu () {
if [[ $MACHINE_OS == "mac" ]]; then
brew install ncdu
elif [[ $MACHINE_OS == "linux" ]]; then
sudo apt install ncdu
fi
}
fi


# -- php-relay
help_software[php-relay]="Install php-relay"
function php-relay () {
_loading "Installing php-relay"
_loading3 "Adding repo to apt"
curl -s https://repos.r2.relay.so/key.gpg | sudo apt-key add -
sudo add-apt-repository "deb https://repos.r2.relay.so/deb $(lsb_release -cs) main"
sudo apt update
_loading3 "Installing php-relay package"
sudo apt install php-relay
_success "Installed php-relay default PHP vesion"
echo "Other versions can be installed with 'apt-get install php8.1-relay'"
echo "Litespeed or Openlitespeed servers need additional configuration see kb php-relay.md"
}

# -- goaccess
help_software[goaccess]="Install goaccess latest"
function software_goaccess () {
if [[ $MACHINE_OS == "linux" && $MACHINE_OS_FLAVOUR == "debian" ]]; then
wget -O - https://deb.goaccess.io/gnugpg.key | gpg --dearmor | sudo tee /usr/share/keyrings/goaccess.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/goaccess.gpg arch=$(dpkg --print-architecture)] https://deb.goaccess.io/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/goaccess.list
sudo apt-get update
sudo apt-get install goaccess
else
_error "goaccess not supported on $MACHINE_OS"
fi
}

13 changes: 4 additions & 9 deletions cmds/cmds-system.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function cpu () {
elif (( $(echo "$CPU_MHZ < 3.5" | bc -l) )); then
CPU_CHECK=$(_warning "CPU Mhz = $CPU_MHZ and is between 3Ghz and 3.5Ghz" 0)
else
CPU_CHECK="CPU Mhz = $CPU_MHZ and is 3.5Ghz or above"
CPU_CHECK=$(_success "CPU Mhz = $CPU_MHZ and is 3.5Ghz or above")
fi
fi

Expand All @@ -60,16 +60,16 @@ function cpu () {
# -- mem
help_system[mem]='Get memory information'
function mem () {
if [[ $OS_MACHINE == "linux" ]]; then
if [[ $MACHINE_OS == "linux" ]]; then
# -- Memory
MEM=$(free -m | awk 'NR==2 {printf "%s MB used, %s MB free, %s MB cached", $3, $4, $6}')
MEM=$(free -m | awk 'NR==2 {printf "Total: %s MB, Used:%s MB, Free: %s MB, Cached: %s MB",$2, $3, $4, $6}')

# -- Swappiness
[[ -f /proc/sys/vm/swappiness ]] && SWAP="/proc/sys/vm/swappiness: $(cat /proc/sys/vm/swappiness)" || _error "Can't find swap" 0

# -- Print out Memory and Swap
echo "Memory: $MEM | Swap: $SWAP"
elif [[ $OS_MACHINE == "mac" ]]; then
elif [[ $MACHINE_OS == "mac" ]]; then
MEM=$(sysctl hw.memsize | awk '{print $2/1024/1024}')
MEM_USED=$(echo "scale=2; ${MEM} - $(memory_pressure | grep "Pages free" | awk '{print $3/1024}') - $(memory_pressure | grep "Pages active" | awk '{print $3/1024}') - $(memory_pressure | grep "Pages inactive" | awk '{print $3/1024}') - $(memory_pressure | grep "Pages speculative" | awk '{print $3/1024}') - $(memory_pressure | grep "Pages wired down" | awk '{print $4/1024}')" | bc)
MEM_CACHED=$(vm_stat | awk '/^Pages free:/ {free=$3} /^Pages speculative:/ {spec=$3} /^Pages inactive:/ {inactive=$3} /^Pages wired down:/ {wired=$4} END {printf "%.1f MB\n", (free+spec+inactive+wired)*4096/1048576}')
Expand All @@ -85,13 +85,8 @@ function mem () {
# -- sysinfo
help_system[sysinfo]='Get system information'
sysinfo () {
_loading "CPU"
cpu
_loading "Memory"
mem
_loading "Disk"
disk
_loading "Short Format"
}

help_system[count-files-directories]='Count files and directories'
Expand Down
6 changes: 6 additions & 0 deletions cmds/cmds-wordpress.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,9 @@ function wp-cli-install () {
echo "wp-cli installed"
fi
}

# -- wp-profile
help_wordpress[wp-profile]='Install wp-cli-profile-command module'
function wp-profile () {
wp package install wp-cli/profile-command
}
59 changes: 59 additions & 0 deletions cron.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash
# -- Created by jordantrizz -- Version 0.0.1
# -- Purpose: Run cron and log the output to stdout, syslog, or a file.
# -- Usage: Add the following to your crontab
# */5 * * * * /home/systemuser/cron.sh

# Important Variables
SCRIPT_DIR=$(dirname "$(realpath "$0")")
CRON_CMD=""

# Settings
LOG_TO_STDOUT="1" # - Log to stdout? 0 = no, 1 = yes
LOG_TO_SYSLOG="1" # - Log to syslog? 0 = no, 1 = yes
LOG_TO_FILE="0" # - Log to file? 0 = no, 1 = yes
LOG_FILE="/home/app.goodmorningleland.com/wordpress-crons.log" # Location for wordpress cron.
HEARTBEAT_URL="https://uptime.betterstack.com/api/v1/heartbeat/qemxv615Fi8DUjAhzakbdCnE" # - Heartbeat monitoring URL
POST_CRON_CMD="" # - Command to run after cron completes

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

# Run WordPress crons due now and log the output
CRON_OUTPUT=$(eval $CRON_CMD)

# Check if there was an error running wp-cli command
if [[ $? -ne 0 ]]; then
echo "Error: $CRON_CMD - command failed" >&2
echo "$CRON_OUTPUT"
if [[ -n "$POST_CRON_CMD" ]]; then
eval "$POST_CRON_CMD"
fi
exit 1
fi

# Check if heartbeat monitoring is enabled and send a request to the heartbeat URL if it is and there are no errors
if [[ -n "$HEARTBEAT_URL" ]] && [[ $? -eq 0 ]] ; then
curl -I -s "$HEARTBEAT_URL" > /dev/null
fi

# Log the end time and CPU usage
END_TIME=$(date +%s.%N)

# check if bc installed otherwise use awk
if [[ $(command -v bc) ]]; then
TIME_SPENT=$(echo "$END_TIME - $START_TIME" | bc)
else
TIME_SPENT=$(echo "$END_TIME - $START_TIME" | awk '{printf "%f", $1 - $2}')
fi
CPU_USAGE=$(ps -p $$ -o %cpu | tail -n 1)

# Check if logging to syslog is enabled
if [[ $LOG_TO_STDOUT == "1" ]]; then
echo -e "Cron job completed in $TIME_SPENT seconds with $CPU_USAGE% CPU usage. \nOutput: $CRON_OUTPUT"
elif [[ $LOG_TO_SYSLOG == "1" ]]; then
echo -e "Cron job completed in $TIME_SPENT seconds with $CPU_USAGE% CPU usage. \nOutput: $CRON_OUTPUT" | logger -t "cron-script"
elif [[ $LOG_TO_FILE == "1" ]]; then
# Log to file in the WordPress install directory
echo "$(date +"%Y-%m-%d %H:%M:%S") - Cron completed in $TIME_SPENT seconds with $CPU_USAGE% CPU usage. \nOutput: $CRON_OUTPUT" >> $LOG_FILE
fi
84 changes: 84 additions & 0 deletions kb/php-relay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Install Notes
* skill -9 lsphp if module doesnt show up for LSWS
* Install php-relay for CLI version and FPM version as they might differ.

# Install on Litespeed/Openlitespeed
* Following Ubuntu packages install.
* ```cp /usr/lib/php/20190902/relay.so /usr/local/lsws/lsphp74/lib/php/20190902```
* joe /usr/local/lsws/lsphp74/etc/php/7.4/mods-available
```
; The path to the extension binary.
; Relative paths will look in `php-config --extension-dir`.
;
extension = relay.so
; Relay license key (via https://relay.so).
; Without a license key Relay will throttle to 16MB memory one hour after startup.
;
; relay.key =
; The environment Relay is running in.
; Supported values: `production`, `staging`, `testing`, `development`
;
; relay.environment = development
; How much memory Relay allocates on startup. This value can either be a
; number like 134217728 or a unit (e.g. 128M) like memory_limit.
; See: https://php.net/manual/faq.using.php#faq.using.shorthandbytes
;
; Relay will allocate at least 16M for overhead structures.
; Set to `0` to disable in-memory caching and use as client only.
;
; relay.maxmemory = 32M
; At what percentage of used memory should Relay start evicting keys.
;
; relay.maxmemory_pct = 95
; How Relay evicts keys. This has been designed to mirror Redis’
; options and we currently support `noeviction`, `lru`, and `random`.
; The default `noeviction` policy will proxy all uncached commands
; to Redis, once the in-memory cache is full.
;
; relay.eviction_policy = noeviction
; How many keys should we scan each time we process evictions.
;
; relay.eviction_sample_keys = 128
; Default to using a persistent connection when calling `connect()`.
;
; relay.default_pconnect = 1
; The number of databases Relay will create per in-memory cache.
; This setting should match the `databases` setting in your `redis.conf`.
;
; relay.databases = 16
; The maximum number of PHP workers that will have their own in-memory cache.
; While each PHP worker will have its own connection to Redis, not all
; workers need their own in-memory cache and can be read-only workers.
;
; This setting is per connection endpoint (distinct Redis connections),
; e.g. connecting to two separate instances will double the workers.
;
; relay.max_endpoint_dbs = 32
; The number of epoch readers allocated on startup.
;
; relay.initial_readers = 128
; How often (in microseconds) Relay should proactively check the
; connection for invalidation messages from Redis.
;
; relay.invalidation_poll_freq = 5
; Whether Relay should log debug information.
; Supported levels: `debug`, `verbose`, `notice`, `error`, `off`
;
; relay.loglevel = off
; The path to the file in which information should be logged, if logging is enabled.
;
; relay.logfile = /tmp/relay.log
```
Loading

0 comments on commit a4ff017

Please sign in to comment.