Skip to content

Instantly share code, notes, and snippets.

View katopz's full-sized avatar
🦀
Rust me if you can

Todsaporn Banjerdkit katopz

🦀
Rust me if you can
View GitHub Profile
@katopz
katopz / setup-container.sh
Created July 22, 2016 14:48
For setup Docker container and use data volume for db.
#!/bin/bash
CONTAINER_INDEX=$1
CONTAINER_NAME="mongo"$1
DATA_VOLUME="mongo-data-volume"$1
mkdir $CONTAINER_NAME
DB_PORT=$((30000+$CONTAINER_INDEX))
HTTP_PORT=$((28017+$CONTAINER_INDEX))
NETWORK_NAME=$2
REPLICASET_NAME=$3
#!/bin/bash
CONTAINER_INDEX=$1
CONTAINER_NAME="mongo"$1
mkdir $CONTAINER_NAME
DB_PORT=$((30000+$CONTAINER_INDEX))
HTTP_PORT=$((28017+$CONTAINER_INDEX))
NETWORK_NAME=$2
REPLICASET_NAME=$3
# Set oplog size.
oplogSizeMB=128
@katopz
katopz / setup.sh
Last active July 22, 2016 14:48
For setup 3 MongoDB replica set in Docker container, will need https://gist.github.com/katopz/9d7519f958b11bc368be97a536fd1e8d
## Setup Docker
NETWORK_NAME=${1:-my-mongo-cluster}
REPLICASET_NAME=${2:-my-mongo-set}
# Remove old network if has.
docker network rm my-mongo-cluster
# Create docker network name.
docker network create $NETWORK_NAME
# List docker network.
docker network ls
@katopz
katopz / setup-go-swarmkit.sh
Last active July 18, 2016 20:01
Lazy setup go lang for build swarmkit
# Install homebrew.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# Install go.
brew install go
# Export path as homebrew suggest.
echo export PATH=$PATH:/usr/local/opt/go/libexec/bin >> ~/.bashrc
# Export gopath to $HOME/go
echo 'export GOPATH=$HOME/go' >> ~/.bash_profile
# Excute bash_profile.
. ~/.bash_profile
@katopz
katopz / install-docker-exp.sh
Last active December 19, 2020 11:41
Install Docker on Ubuntu 14.04.4 x64
# Install Docker on Ubuntu 14.04.4 x64
# Ref https://docs.docker.com/engine/installation/linux/ubuntulinux/
# No interactive for now.
export DEBIAN_FRONTEND=noninteractive
# Update your APT package index.
sudo apt-get -y update
# Update package information, ensure that APT works with the https method, and that CA certificates are installed.
sudo apt-get -y install apt-transport-https ca-certificates
# Add the new GPG key.
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
#!/bin/bash
RS_INDEX=$1
RS_NAME="rs"$1
mkdir $RS_NAME
PORT=$((27017+$RS_INDEX))
cat <<EOF > $RS_NAME.conf
systemLog:
destination: file
path: "var/log/mongodb/mongod.log"
logAppend: true
@katopz
katopz / setup.sh
Last active May 1, 2020 12:40
Basic setup for 2 replica set. will need rs.sh at https://gist.github.com/katopz/da912b3fa2677b5f149fd01e5243e28a
# List existing mongo process
pgrep mongo
# Kill existing process if has.
pkill mongo
# Clear old folder if has.
rm -rf rs0 && rm -rf rs1
# Create log folder.
mkdir -p ./var/log/mongodb
# Create replica set 0
. rs.sh 0
@katopz
katopz / docker-cleanup
Created May 15, 2016 14:23
Cleanup docker files: untagged containers and images.
#!/bin/sh
# Cleanup docker files: untagged containers and images.
# https://github.com/blueyed/dotfiles/blob/master/usr/bin/docker-cleanup
# Use `docker-cleanup -n` for a dry run to see what would be deleted.
untagged_containers() {
# Print containers using untagged images: $1 is used with awk's print: 0=line, 1=column 1.
# NOTE: "[0-9a-f]{12}" does not work with GNU Awk 3.1.7 (RHEL6).
# Ref: https://github.com/blueyed/dotfiles/commit/a14f0b4b#commitcomment-6736470
docker ps -a | tail -n +2 | awk '$2 ~ "^[0-9a-f]+$" {print $'$1'}'
@katopz
katopz / install-docker-compose.sh
Last active July 14, 2019 14:12
Will install Docker Compose 1.7.1 Ref https://docs.docker.com/compose/install/
# Will install Docker Compose 1.7.1
# Ref https://docs.docker.com/compose/install/
# You can get version number from https://github.com/docker/compose/releases
curl -L https://github.com/docker/compose/releases/download/1.7.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
# Apply executable permissions to the binary:
chmod +x /usr/local/bin/docker-compose
# Test the installation.
docker-compose --version
# Expected docker-compose version 1.7.1, build 0a9ab35
@katopz
katopz / install-docker.sh
Last active May 17, 2016 19:15
Install Docker on Ubuntu 14.04
# Install Docker on Ubuntu 14.04
# Ref https://docs.docker.com/engine/installation/linux/ubuntulinux/
# Update your APT package index.
sudo apt-get update
# Ensure that APT works with the https method, and that CA certificates are installed.
sudo apt-get install apt-transport-https ca-certificates
# Add the new GPG key.
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
# Add docker.list
sudo echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" > /etc/apt/sources.list.d/docker.list