Skip to content

Instantly share code, notes, and snippets.

View eksiscloud's full-sized avatar

Jakke Lehtonen eksiscloud

View GitHub Profile
@eksiscloud
eksiscloud / services.mon
Last active January 9, 2021 07:32
Monit conf for Varnish, Redis, Hitch and Postfix
# Varnish
check program varnishpanic with path "/bin/varnishadm panic.show"
if status != 1 then alert
check process varnish with pidfile /var/run/varnish.pid
#start program = "/etc/init.d/varnish start" with timeout 30 seconds
#stop program = "/etc/init.d/varnish stop"
start program = "/usr/bin/systemctl start varnish" with timeout 30 seconds
stop program = "/usr/bin/systemctl stop varnish"
if failed host 127.0.0.1 port 80 protocol http
@eksiscloud
eksiscloud / worpdress-site.mon
Created October 21, 2019 07:32
Monit conf for a host/domain/site with Wordpress
### example.tld
check host example.tld with address www.example.tld
# ICMP check
if failed icmp type echo
for 2 times within 2 cycles
then alert
# HTTP check
if failed port 80 protocol http
@eksiscloud
eksiscloud / lamp.mon
Last active October 22, 2019 21:54
Monit: Apache2, MySQL and PHP-FPM
# Apache2
check process apache2 with pidfile /var/run/apache2/apache2.pid
group www-data
start program = "/bin/systemctl start apache2" with timeout 30 seconds
stop program = "/bin/systemctl stop apache2"
if failed host localhost port 80 with protocol http
and request "/server-status" for 2 times within 2 cycles then restart
depend apache_bin
depend apache_rc
@eksiscloud
eksiscloud / site.mon
Last active October 21, 2019 01:52
Monit conf for a host/domain/site
### example.tld
check host example.tld with address www.example.tld
# ICMP check
if failed icmp type echo
for 2 times within 2 cycles
then alert
# HTTP check
if failed port 80 protocol http
@eksiscloud
eksiscloud / monitrc
Last active October 28, 2019 18:45
Starting point for new install of Monit server monitoring
set daemon 60 #check services every 60 seconds
set logfile /var/log/monit.log
set idfile /var/lib/monit/id
set statefile /var/lib/monit/state
#Event queue
set eventqueue
basedir /var/lib/monit/events # set the base directory where events will be stored
slots 100 # optionally limit the queue size
@eksiscloud
eksiscloud / functions.php
Last active September 4, 2023 15:23
Delete coupons of Woocommerce when those are expired
/**
* add this in the functions.php of theme/child theme/snippets plugin
* Schedule the daily event if necessary.
*/
function schedule_delete_expired_coupons() {
if ( ! wp_next_scheduled( 'delete_expired_coupons' ) ) {
wp_schedule_event( time(), 'daily', 'delete_expired_coupons' );
}
}
add_action( 'init', 'schedule_delete_expired_coupons' );
@eksiscloud
eksiscloud / example.com.conf
Created August 5, 2019 20:19
Very general example.com.conf @ Hitch/Varnish (Apache2, Wordpress, WP Rocket, EWWW, NinjaFirewall)
<VirtualHost 127.0.0.1:8080>
ServerAdmin email@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
@eksiscloud
eksiscloud / poista-yleinen.sh
Last active August 2, 2019 22:08
Poistaa Wordpress-artikkelista oletusluokan Yleinen, jos artikkelilla on vähintään yksi toinenkin luokka (WP-CLI)
#!/bin/bash
for post in $(wp post list --field=ID)
do
count=$(wp post term list $post 'category' --fields='name' --format="count")
if [ "$count" -gt "1" ]
then wp post term remove $post category 'yleinen'
fi
done
## chmod 755 poista-yleinen.sh
@eksiscloud
eksiscloud / remove-category.sh
Created August 2, 2019 22:00
Remove uncategorized from Wordpress posts if there is some other category too
#!/bin/bash
for post in $(wp post list --field=ID)
do
count=$(wp post term list $post 'category' --fields='name' --format="count")
if [ "$count" -gt "1" ]
then wp post term remove $post category 'uncategorized'
fi
done
## chmod 755 remove-category.sh
@eksiscloud
eksiscloud / .htaccess
Last active October 23, 2019 11:09
Redirect a site to new domain
# Rewriting on
RewriteEngine on
# redirect to same page in the new site as where a user was in the old site
RewriteBase /
RewriteCond %{SERVER_NAME} =old-domain.com [OR]
RewriteCond %{SERVER_NAME} =new-domain.com
RewriteRule ^ http://new.domain.com%{REQUEST_URI} [END,NE,R=301]