Skip to content

Instantly share code, notes, and snippets.

View mshafiee's full-sized avatar

Mohammad Shafiee mshafiee

View GitHub Profile
@mshafiee
mshafiee / haproxy.cfg
Last active June 13, 2022 10:34
Sample of HAProxy active-active peers rate limiting by counting a custom header
global
localpeer haproxy-1
defaults
timeout connect 5s
timeout client 1m
timeout server 1m
peers haproxy-peers
@mshafiee
mshafiee / bash.sh
Created May 12, 2022 11:57
bash cheatsheets
#!/bin/bash
##############################################################################
# SHORTCUTS and HISTORY
##############################################################################
CTRL+A # move to beginning of line
CTRL+B # moves backward one character
CTRL+C # halts the current command
CTRL+D # deletes one character backward or logs out of current session, similar to exit
CTRL+E # moves to end of line
@mshafiee
mshafiee / clean.sh
Created May 12, 2022 11:39
Free up disk space on Ubuntu - clean log, cache, archive packages/apt archives, orphaned packages, old kernel and remove the trash
#!/bin/sh
#Check the Drive Space Used by Cached Files
du -sh /var/cache/apt/archives
#Clean all the log file
#for logs in `find /var/log -type f`; do > $logs; done
logs=`find /var/log -type f`
for i in $logs
@mshafiee
mshafiee / install-latest-docker.sh
Created May 12, 2022 11:26
Install Latest Docker and Docker-compose on Ubuntu
# Ask for the user password
# Script only works if sudo caches the password for a few minutes
sudo true
# Install kernel extra's to enable docker aufs support
# sudo apt-get -y install linux-image-extra-$(uname -r)
# Add Docker PPA and install latest version
# sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
# sudo sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
@mshafiee
mshafiee / join-ubuntu-to-ad-dc.sh
Last active May 11, 2022 12:00
Join Ubuntu 20.04.4 to Active Directory Domain
#!/bin/bash
JDC_ORG_UNIT=""
JDC_ORG_ENV=""
JDC_DOMAIN_NAME=mydomain.com
JDC_AD_DC1_IP=192.168.240.11
JDC_AD_DC2_IP=192.168.240.12
JDC_AD_DC1_NAME=dc1-inf-ad-ds1.mydomain.com
JDC_AD_DC2_NAME=dc1-inf-ad-ds2.mydomain.com
JDC_HOST_NAME=$(hostname | awk -F'.' '{print $1}').$JDC_DOMAIN_NAME
JDC_GROUP_PREFIX="os"
@mshafiee
mshafiee / netplan-set-custom-dns.sh
Created May 8, 2022 13:36
Ubuntu 20.04.4 - Scripting Netplan for custom DNS address
sudo snap install yq
sudo cp /etc/netplan/00-installer-config.yaml /etc/netplan/00-installer-config.yaml.bk_`date +%Y%m%d%H%M`
cat /etc/netplan/00-installer-config.yaml | yq -e '.network.ethernets.ens160.nameservers.addresses[0]="192.168.10.11" | .network.ethernets.ens160.nameservers.addresses[1]="192.168.10.12"' | sudo tee /etc/netplan/00-installer-config.yaml
sudo netplan apply
@mshafiee
mshafiee / limit_docker_resources_usage.txt
Last active May 7, 2022 05:23
Limit docker resources usage
# vi /etc/systemd/system/docker_limit.slice
[Unit]
Description=Slice that limits docker resources
Before=slices.target
[Slice]
CPUAccounting=true
CPUQuota=700%
# Memory Management
============================
Create XFS Volume
============================
sudo apt-get install xfsprogs xfsdump
sudo wipefs -a /dev/sdb
sudo fdisk /dev/sdb # g -> n -> p -> 1 -> w
sudo pvcreate /dev/sdb1
sudo vgcreate data-vg /dev/sdb1
sudo lvcreate -l 100%FREE -n data-lv data-vg
@mshafiee
mshafiee / dump-kubernetes-secrets.sh
Last active January 9, 2021 17:35
Dump all secrets from all namespaces
Dump all secrets from all namespaces and store them in seprate yaml file:
kubectl get secret -A -o custom-columns=:.metadata.name,:.metadata.namespace --no-headers | \
xargs -n 2 sh -c '(kubectl get secret -n $3 -o yaml $2; echo "---") >> $3-$2.yaml' -- {}
.

Docker compose as a systemd unit

Create file /etc/systemd/system/myservice.service. SystemD calling binaries using an absolute path. In my case is prefixed by /usr/local/bin, you should use paths specific for your environment.

[Unit]
Description=%i service with docker compose
Requires=docker.service
After=docker.service