Skip to content

Instantly share code, notes, and snippets.

View Markbnj's full-sized avatar

Mark Betz Markbnj

View GitHub Profile
@Markbnj
Markbnj / haproxy-install.sh
Created August 11, 2015 21:13
Install haproxy
sudo apt-add-repository ppa:vbernat/haproxy-1.5
sudo apt-get update
sudo apt-get -qy install haproxy
sudo cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.orig
# To enable logging edit /etc/rsyslog.conf to match the following:
#
# provides UDP syslog reception
# $ModLoad imudp
# $UDPServerRun 514
@Markbnj
Markbnj / Dockerfile
Created August 11, 2015 21:19
Dockerfile for a simple redis server
# Dockerfile for building a redis server
FROM ubuntu:15.04
MAINTAINER Someone <someone@some.where>
# install and configure redis from source
RUN cd /home/root && \
wget -q http://download.redis.io/redis-stable.tar.gz && \
tar xvzf redis-stable.tar.gz && \
cd redis-stable && \
@Markbnj
Markbnj / remove-containers.sh
Created August 11, 2015 21:21
Stop and remove all Docker containers
sudo docker stop $(sudo docker ps -a -q)
sudo docker rm $(sudo docker ps -a -q)
@Markbnj
Markbnj / remove-images.sh
Created August 11, 2015 21:22
Remove all Docker images
sudo docker rmi $(sudo docker images -a -q)
@Markbnj
Markbnj / simple-redis-log-handler.py
Created August 12, 2015 16:56
Simple redis log handler for python
import logging
import redis
class RedisLogHandler(logging.Handler):
"""
Class used to emit log messages to a redis list
"""
def __init__(self, host, port, key, db=0, formatter=None, level=logging.NOTSET):
logging.Handler.__init__(self, level)
@Markbnj
Markbnj / install-pip.sh
Created August 23, 2015 02:48
Install updated pip
# get rid of the version installed with ubuntu
sudo apt-get remove --auto-remove python-pip
# get the official installer
wget https://bootstrap.pypa.io/get-pip.py
# install it
sudo -H python get-pip.py
@Markbnj
Markbnj / removepyc.sh
Created August 23, 2015 18:37
Recursively remove all .pyc files from a python project
find . -name "*.pyc" -exec rm -rf {} \;
@Markbnj
Markbnj / cmdline-example.sh
Created August 24, 2015 19:18
Handling command line options in bash scripts, example
# Starts the elasticsearch node container, optionally setting
# a cluster name and host IP to expose to other nodes. Mounts
# the directory at /var/lib/elasticsearch to the same location
# on the host.
#
# exposes ports:
# 9200 = elasticsearch http
# 9300 = elasticsearch transport
#
IP=""
@Markbnj
Markbnj / getch.py
Created August 26, 2015 17:05
Get a single key press from the terminal in python
import termios
import sys
import tty
def _getch():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(fd)
ch = sys.stdin.read(1)
@Markbnj
Markbnj / update-policy.sh
Created September 15, 2015 06:33
Allow services to start in an Ubuntu 15.04 Docker container
# By default the /usr/sbin/policy-rc.d script in the ubuntu:15.04 docker image is set to return 101
# (action forbidden by policy) every time it is invoked. This prevents systemctl start requests for
# services from completing succesfully. The following command overwrites the contents of policy-rc.d
# to allow service starts.
#
# Note that this won't work right under bash due to expansion of the '!' character. Docker uses sh
# by default when executing the commands in the dockerfile, so this will work there, and you can
# also use sh interactively to run this.
echo "#!/bin/sh\nexit 0" > /usr/sbin/policy-rc.d