Skip to content

Instantly share code, notes, and snippets.

@roojs
roojs / mysqlrouter_check
Last active March 2, 2022 09:25
mysqlrouter_check
#!/bin/bash
#usage in cron... /mysqlrouter_check cluster-hk2 mysqluser mysqlpass
match=$1
mysqluser=$2
mysqlpass=$3
routerpid=$(/bin/pidof mysqlrouter)
#!/bin/sh
########################################################
# #
# www.361way.com #
# Useage: check_traffic -i Interface -w warn -c cirt #
# it's for pnp4nagios check the traffic #
# based on https://exchange.nagios.org/directory/Plugins/Network-Connections%2C-Stats-and-Bandwidth/check_traffic_pnp4naios/details
########################################################
#!/bin/bash
#
#command[check_memory]=/usr/lib/nagios/plugins/check_memory -w 10 -c 5
#
#
USAGE="`basename $0` [-w|--warning]<percent free> [-c|--critical]<percent free>"
THRESHOLD_USAGE="WARNING threshold must be greater than CRITICAL: `basename $0` $*"
calc=/tmp/memcalc
percent_free=/tmp/mempercent
@roojs
roojs / nagios-add-stuff.php
Last active June 22, 2022 01:50
script to install nagios montioring tool, output server config, so it can be copy and pasted to monitoring server
#!/usr/bin/php
<?php
# tool to try and reduce the work required to add nagios plugins to servers, and their lxc client
# usage: log into server, and run
# curl http:///{the gist url}/nagios-add-stuff.php | sudo php
# functions
$GLOBALS['added_first_br'] = array(); // array of files that we have added the line break.
deb http://deb.debian.org/debian bookworm main contrib
deb http://deb.debian.org/debian-security/ bookworm-security main contrib
deb http://deb.debian.org/debian bookworm-updates main contrib
deb http://mirrors.linode.com/debian bookworm main contrib
deb http://mirrors.linode.com/debian-security/ bookworm-security main contrib
deb http://mirrors.linode.com/debian bookworm-updates main contrib
#!/bin/bash
# find the last error - so it might change if we fix it...
# core:error - not php code related
# not found or unable to stat - are just hackers trying to break in.. can ignore
RES=$(/bin/grep PHP /var/log/apache2/error.log | /usr/bin/egrep -v 'PHP\s+[0-9]+' | /bin/grep -v 'PHP Stack' | grep -v 'Deadlock found when trying to get lock' | grep -v max_input_vars | /usr/bin/tail -1)
if [[ ( $RES == "" ) ]]; then
echo "OK"
else
#tends to bork containers getty + just a mess
apt install -y sysvinit-core systemd-sysv-
#reboot
apt remove -y systemd
apt-mark hold systemd systemd-sysv
#nice cleanup
apt autoremove --purge
#!/bin/sh
## you might want to add some user authentication here
# from - https://tech.labelleassiette.com/how-to-reduce-the-memory-usage-of-mysql-61ea7d1a9bd
# (credits to Eduardo Franceschi)
mysql -e "show variables; show status" | awk '
{
VAR[$1]=$2
}
END {
#this fixes booting with new kernels - breaking cgroups on lxc and /dev/net/tun not being available in containers
GRUB_CMDLINE_LINUX="console=ttyS0,19200n8 net.ifnames=0 systemd.unified_cgroup_hierarchy=false systemd.legacy_systemd_cgroup_controller=false cgroup_enable=memo
ry swapaccount=1"
@roojs
roojs / default-debian.conf
Last active November 28, 2023 01:56
fail2ban - jail.d debian default
#try and get those sneaky slow brute force ssh attackers to slow down
[sshd]
enabled = true
port = 8022
maxretry=3
bantime = 24h
findtime = 1d