Skip to content

Instantly share code, notes, and snippets.

View kamermans's full-sized avatar
😏

Steve Kamerman kamermans

😏
View GitHub Profile
@kamermans
kamermans / cleanup_releases.pl
Created April 16, 2015 02:20
Capistrano releases batch cleanup script
#!/bin/bash
ROOT_DIR="/u/apps"
KEEP_RELEASES=5
echo "Cleaning releases folders (retaining $KEEP_RELEASES):"
for APP_DIR in $(find $ROOT_DIR -maxdepth 2 -type d -name releases); do
CURRENT_RELEASE=$(readlink -f "$APP_DIR/../current" | xargs basename)
echo " $APP_DIR (current: $CURRENT_RELEASE)"
@kamermans
kamermans / rsyslog.conf
Last active April 24, 2018 01:40
RainerScript version of /etc/rsyslog.conf for Ubuntu with rsyslog 8+
# /etc/rsyslog.conf Configuration file for rsyslog.
#
# For more information see
# /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html
#
# Default logging rules can be found in /etc/rsyslog.d/50-default.conf
#
# WARNING: This config has been converted to RainerScript format which could
# affect config files provided by other software in /etc/rsyslog.d/
# It should behave the same as the legacy-format config file that ships
@kamermans
kamermans / configure_docker0.sh
Last active April 26, 2024 00:58
Change the IP subnet of Docker's docker0 interface
#!/bin/sh -e
#
# NOTE: Since Docker 1.10 (February 4, 2016), it has been possible to configure the
# Docker daemon using a JSON config file. On Linux, this file is normally located at
# /etc/docker/daemon.json. You should use this JSON config method if you are running
# a version of Docker that is at least 1.10!
# Here is an example configuration that sets the docker0 bridge IP to 192.168.254.1/24:
# {
# "bip": "192.168.254.1/24"
# }
@kamermans
kamermans / start_solr.sh
Created May 16, 2015 22:25
BlueSpice ExtendedSearch in a Docker container
#!/bin/bash
###################################################
# BlueSpice ExtendedSearch in a box, er, container
#
# This script runs the Java / Tomcat / Solr apps inside a container using Docker so they don't need
# to be installed on your local server at all.
#
# Installation:
# 1. Install Docker: https://docs.docker.com/installation/, then do this:
# 2. mkdir -p /opt/bluespice_data
@kamermans
kamermans / docker_ephemeral_create.sh
Last active September 22, 2022 18:32
AWS EC2 script to mount Instance Store 0 and 1 as Docker temp and volume storage
#!/bin/sh -e
# This script will DESTROY /dev/xvdb and /dev/xvdc and remount them
# for Docker temp and volume storage.
# It is intended for EC2 instances with 2 ephemeral SSD instance stores
# like the c3.xlarge instance type.
service docker stop || true
# Setup Instance Store 0 for Docker Temp
# (set in /etc/default/docker)
@kamermans
kamermans / .bash_git.sh
Created May 22, 2015 19:04
A better bash-git prompt using git-prompt
# A better bash-git prompt using git-prompt
# https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh
LIGHT_WHITE="\[\033[1;37m\]"
WHITE="\[\033[0;37m\]"
GRAY="\[\033[1;30m\]"
BLACK="\[\033[0;30m\]"
RED="\[\033[0;31m\]"
LIGHT_RED="\[\033[1;31m\]"
GREEN="\[\033[0;32m\]"
@kamermans
kamermans / set_php_fpm_affinity.sh
Created June 11, 2015 05:29
Set PHP-FPM pool workers CPU affinity so each worker gets one CPU core
#!/bin/bash
# Set PHP-FPM pool workers CPU affinity so each worker gets one CPU core
# Note that FPM recycles threads, so you'll need to run this on cron periodically
# Author: Steve Kamerman
CPUS=$(grep -c CPU /proc/cpuinfo)
FPM_PIDS=$(ps auxw | grep php-fpm | grep pool | awk '{ print $2; }')
if [ "$FPM_PIDS" = "" ]; then
@kamermans
kamermans / docker-clear.sh
Last active October 12, 2016 03:20
Clear orphaned cgroups that prevent Docker from starting containers
#!/bin/bash
# This script fixes the Docker error that prevents containers from being (re)started
# with an error message like this:
# Cannot start container 7831d3502e: [8] System error: Unit docker-7831d3502e.scope already exists.
echo "Stopping Docker containers"
docker stop $(docker ps -q) > /dev/null 2>&1
echo "Clearing orphaned cgroups"
@kamermans
kamermans / result.txt
Created October 26, 2015 23:34
PHP time() vs microtime() vs microtime(true) benchmark
PHP
--------------------------------------------------------------
Total Iterations: 10,000,000
time(): 0.73976612091064 seconds (13,517,785/sec)
microtime(): 4.2245488166809 seconds (2,367,116/sec)
microtime(true): 1.2555038928986 seconds (7,964,929/sec)
HHVM
--------------------------------------------------------------
Total Iterations: 10,000,000
@kamermans
kamermans / upgrade_docker.sh
Last active June 13, 2016 18:54
Upgrade Docker and Docker-Compose while deleting all containers and migrating storage
#!/bin/sh -e
# Upgrade Docker to 1.10 from 1.8+
# curl -sSL https://gist.githubusercontent.com/kamermans/3b33d1b36c4bf570415c/raw/upgrade_docker.sh | sh
echo "Upgrading Docker Compose" && sleep 2
COMPOSE=$(which docker-compose || echo /usr/local/bin/docker-compose)
curl -L https://github.com/docker/compose/releases/download/1.6.0/docker-compose-`uname -s`-`uname -m` > $COMPOSE
chmod +x $COMPOSE
echo "Migrating Docker data to 1.10+ format" && sleep 2