Skip to content

Instantly share code, notes, and snippets.

View pwilken's full-sized avatar
🌞
just another wonderful day

Pierre Wilken pwilken

🌞
just another wonderful day
View GitHub Profile
@pwilken
pwilken / rancher-kubernetes-clean-nodes.sh
Last active November 8, 2019 09:24
Rancher/Kubernetes Clean Nodes
#!/bin/sh
docker rmi $(docker images -a -q)
docker rm -f $(docker ps -qa)
docker volume rm $(docker volume ls -q)
cleanupdirs="/var/lib/etcd /etc/kubernetes /etc/cni /opt/cni /var/lib/cni /var/run/calico /opt/rke"
for dir in $cleanupdirs; do
echo "Removing $dir"
rm -rf $dir
done
@pwilken
pwilken / cleanup_s3_policy.py
Last active May 30, 2023 13:30
AWS Lambda function for deleting files from S3 bucket, filename contains timestamp. Clean up for everything older then 7 days. Triggered once a week by a CloudWatch Event.
import logging
import boto3
import datetime
from botocore.exceptions import ClientError
def lambda_handler(event, context):
# Set up logging
logging.basicConfig(level=logging.DEBUG,
format='%(levelname)s: %(asctime)s: %(message)s')
@pwilken
pwilken / service_up_check_with_lambda_invoke.py
Created July 1, 2019 13:23
AWS Lambda function, checks if service is reachable and if not calls an other Lambda function. Don`t forget to give your function the rights to call other lambda functions.
import subprocess
import boto3
import json
lambda_client = boto3.client('lambda')
def lambda_handler(event, context):
result = subprocess.call("curl -I YOUR_URL", shell=True)
if result > 0:
@pwilken
pwilken / twilio_lambda_function.py
Created July 1, 2019 13:27
Use Twilio API with lambda function over AWS API Gateway.
import base64
import json
import os
import urllib
from urllib import request, parse
TWILIO_SMS_URL = "https://api.twilio.com/2010-04-01/Accounts/{}/Messages.json"
TWILIO_CALL_URL = "https://api.twilio.com/2010-04-01/Accounts/{}/Calls.json"
TWILIO_ACCOUNT_SID = os.environ.get("TWILIO_ACCOUNT_SID")
@pwilken
pwilken / charset-settings-linux-docker.txt
Last active July 2, 2019 13:01
German UTF-8 example. Charset encoding needs to be generated in the Dockerfile.
ENV LANG="de_DE.UTF-8"
ENV LC_COLLATE="de_DE.UTF-8"
ENV LC_CTYPE="de_DE.UTF-8"
ENV LC_MESSAGES="de_DE.UTF-8"
ENV LC_MONETARY="de_DE.UTF-8"
ENV LC_NUMERIC="de_DE.UTF-8"
ENV LC_TIME="de_DE.UTF-8"
RUN locale-gen de_DE.UTF-8
RUN update-locale LANG=de_DE.UTF-8
@pwilken
pwilken / postgresql-performance-problems.sql
Created July 9, 2019 10:18
PostgreSQL Performance Problems
-- Check active queries
SELECT * FROM pg_stat_activity WHERE state = 'active';
-- Terminate active queries with ProcessID
select pg_terminate_backend(pid);
-- Get all queries which are older then 5 minutes (idle or active)
SELECT pid, now() - pg_stat_activity.query_start AS duration, query, state
FROM pg_stat_activity WHERE (now() - pg_stat_activity.query_start) > interval '5 minutes';
@pwilken
pwilken / psql_cleanup_queries.sql
Last active July 9, 2019 14:47
Stored Function, cleanup postgresql queries.
create type query_datatype as (pid int, duration text, query text);
drop type query_datatype cascade;
drop function terminate_performance_killer();
create OR REPLACE FUNCTION terminate_performance_killer() RETURNS SETOF query_datatype
LANGUAGE plpgsql
AS $$
DECLARE
items query_datatype;
#!/bin/bash
USERNAME=root
ssh -l ${USERNAME} server-name "
sudo apt-get install nfs-common;
cd ..;
sudo mkdir -p /remote-backups;
sudo chmod 777 remote-backups;
sudo mount -t nfs "backup-storage-id:/export/ftpbackup/ovh-server-name" /remote-backups;
exit;
dpkg -l | grep -i docker
sudo apt-get purge -y docker-engine docker docker.io docker-ce
sudo apt-get autoremove -y --purge docker-engine docker docker.io docker-ce
sudo rm -rf /var/lib/docker /etc/docker
sudo rm /etc/apparmor.d/docker
sudo groupdel docker
sudo rm -rf /var/run/docker.sock
dpkg -l | grep -i docker;
sudo apt-get purge -y docker-engine docker docker.io docker-ce;
sudo apt-get autoremove -y --purge docker-engine docker docker.io docker-ce;
sudo rm -rf /var/lib/docker /etc/docker;
sudo rm /etc/apparmor.d/docker;
sudo groupdel docker;
sudo rm -rf /var/run/docker.sock;