Skip to content

Instantly share code, notes, and snippets.

View lorello's full-sized avatar
🏠
Working from home

LoreLLo lorello

🏠
Working from home
View GitHub Profile
@lorello
lorello / swarm-nodes-cleanup.sh
Created August 21, 2020 15:20
Docker swarm dead workers cleanup
#!/bin/bash
#
# This script clean a docker swarm cluster from all the dead worker nodes
#
# docker node ls output example
# ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
#y4000************e1uv5vdj * boat-manager-c240 Ready Active Reachable 19.03.11
#wlqc4************zywu7z90 boat-manager-cb78 Ready Active Reachable 19.03.8
#i9fz8************rkmn98yh boat-manager-e102 Ready Active Leader 19.03.8
#wgrj7************rj8sglzg boat-tank01-9a5b Down Active 19.03.9
@lorello
lorello / docker-compose.yml
Last active September 1, 2020 11:10
Initialitaion inside yaml file with a long bash command .... example from min.io
createbuckets:
image: minio/mc
networks:
- backplane
depends_on:
- minio
entrypoint: >
/bin/sh -c "
while ! nc -z minio 9000; do echo 'Wait minio to startup...' && sleep 0.1; done;
sleep 5;
@lorello
lorello / backup-dbs.sh
Last active April 17, 2020 17:25
pgdump for a list of db
#!/bin/bash
DB_LIST='sdc
sdc_bugliano
sdc_ala
sdc_treville'
for DB in $DB_LIST; do
pg_dump $DB > $DB.sql
@lorello
lorello / api.md
Created March 18, 2020 10:05
Api snip

GET /devices List device classes POST /devices/create Create a new device class GET /devices/{id} Inspect a device class POST /devices/{id}/update Update a device class DELETE /devices/{id} Delete a device class

@lorello
lorello / Dockerfile
Last active February 19, 2020 21:04
Manage private composer repos during docker build
FROM php:7.2.26-fpm-stretch
# Fixed version with OS Debian strech for the issue here explained
# https://github.com/docker-library/php/issues/865
# Set defaults for variables used by run.sh
ENV COMPOSER_HOME=/root/.composer
# Create Composer directory (cache and auth files) & Get Composer
RUN mkdir -p $COMPOSER_HOME \
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
@lorello
lorello / Dockerfile
Created January 20, 2020 23:15
Container with cron-like scheduling and healthcheck
FROM alpine
RUN set -x \
&& apk update && apk add ca-certificates curl \
&& curl -L https://github.com/odise/go-cron/releases/download/v0.0.7/go-cron-linux.gz | zcat > /usr/local/bin/go-cron \
&& chmod a+x /usr/local/bin/go-cron \
&& apk del ca-certificates
ENV SCHEDULE '@daily'
ENV HEALTHCHECK_PORT 8080
@lorello
lorello / cron-utils-setup.sh
Created December 12, 2019 13:34
run-one: cron utilities from Ubuntu not available on other distros
#!/bin/bash
source_file="https://bazaar.launchpad.net/~run-one/run-one/trunk/download/head:/runone-20110124065624-91p2i9nu34o1aq4k-2/run-one"
other_commands="keep-one-running
run-one-constantly
run-one-until-failure
run-one-until-success
run-this-one"
bin_path=${INSTALL_PATH:-/usr/local/bin}
@lorello
lorello / ec2-custom-name.sh
Last active February 9, 2020 14:11
Customize EC2 hostname
#!/usr/bin/env bash
# set hostname to current name with the last 4 chars of instance id
#
id=$(ec2metadata --instance-id)
myname=${HOSTNAME}-${id:(-4)}
hostnamectl set-hostname $myname
sed -i "s/${HOSTNAME}/${myname}/g" /etc/hosts
echo "New hostname is $myname"
@lorello
lorello / log.sh
Created November 26, 2019 08:35
Simple Log function in Bash
# a simple log function in bash
# usage:
# log "my info message"
# log "my debug message" debug
log_level=info
# uncomment next line to rise up log level
#log_level=debug
log() {
@lorello
lorello / docker-compose-installer.sh
Created November 8, 2019 14:44
Latest version of docker-compose Installer
#!/usr/bin/env bash
set -ex
if [[ ! -f /usr/local/bin/docker-compose ]]; then
sudo apt install -y curl
curl -s https://api.github.com/repos/docker/compose/releases/latest \
| grep browser_download_url \
| grep docker-compose-Linux-x86_64 \
| cut -d '"' -f 4 \