Skip to content

Instantly share code, notes, and snippets.

@XavM
XavM / Install_zbo-goimporter.md
Created October 18, 2016 06:58
Build zbo-goimporter from scratch using Docker

Build zbo-goimporter from scratch (using Docker)

Run a fresh build CT

CT_ID=$(docker run -itd centos /bin/bash)

Enter CT

@XavM
XavM / Install_zbo-ana.md
Last active August 30, 2016 13:04
Build zbo-ana from scratch using Docker

Build zbo-ana from scratch (using Docker)

Run a fresh build CT

CT_ID=$(docker run -itd centos /bin/bash)

Enter CT

@XavM
XavM / curl
Created March 25, 2016 13:59
Pipe any thing to curl's stdin to be http requested, but "flush" curl's stdin every Nth request
## cUrl, used with "-K -", reads the config from the stdin, but waits for stdin's EOF before executing any HTTP requests
## See : http://comments.gmane.org/gmane.comp.web.curl.general/15001
## Using the split's filter options allows starting and piping a stream to a new curl's stdin every N requests
## A same connexion can be kept alive for those N requests, making perfs much much better
## TODO : Find a way to parallelise several curl in a "xargs -P" way
## Example : (the for loop is there to simulate some real stream, and to demonstrate the curl's required format)
@XavM
XavM / gist:12b092eb101a347fdcd2
Created March 7, 2016 14:00
bash job pool for // execution
#!/bin/bash
debug=0;
## Clean up working temp files
function clean_up {
((debug)) || rm -rf "${path_to_file}"
}
trap clean_up EXIT
@XavM
XavM / vps.mount
Created November 4, 2015 15:48
Containers and Service auto registration through Consul for openVZ CT (via ovz action scripts)
#!/bin/bash
set -eo pipefail
CONSUL_EP="IP:PORT"
main() {
# Exit when required files are not present
[[ -f /etc/vz/vz.conf ]] || exit 1
@XavM
XavM / crtct
Created November 4, 2015 15:38
Create an openVZ CT
#!/bin/bash
## Fail fast and be aware of exit codes
set -eo pipefail
# Guess unused CTID, by increasing the last one
get_ct_id() {
#local ctid=$(/usr/sbin/vzlist -H -a -octid \
# 2>/dev/null | tail -1)
#[ -n "$ctid" ] || ctid=100
@XavM
XavM / gist:cb987bb0502305985faa
Last active December 3, 2015 17:00
Clone a (ploop) openVZ CT with base image dedup
#!/bin/bash
# Clone a (ploop) openVZ CT with base image dedup
# Ex : ./vzclone $CTID | xargs vzctl start
set -eo pipefail
if [ -z $1 ]; then
>&2 echo "Usage: vzclone CTID"
exit 1
@XavM
XavM / vztmpl-cr
Last active September 2, 2016 09:49
Create an openVZ template (tar ball) from a running CT
#!/bin/bash
## Create an openVZ template (tar ball) from a running CT
set -eo pipefail
if [ -z $1 ]
then
echo "Usage: vztmpl-cr CTID [NAME]"
exit 1
@XavM
XavM / gist:b3032be9f38e4cdf4f82
Last active August 29, 2015 14:13
dhcp_ct : A "dhcp like" client written in bash and relying on consul catalog (Requires curl, jq, ping and ... consul)
#!/bin/bash
#############
## dhcp_ct : A "dhcp like" client written in bash and relying on consul catalog (Requires curl, jq and ... consul)
## Usage : $> ./dhcp_ct datacenter host_name_prefix ip_pool
## Ex : $> ./dhcp_ct dc1 ct 192.168.0.{1..254} # <- Would register a new node in consul catalog using a free IP and HOSTNAME
## STDOUT : ct1 192.168.0.88
#############
## Fail fast and be aware of exit codes
@XavM
XavM / gist:dfa1153ee5e9fabfec62
Created June 30, 2014 08:25
envconsul runtime.panic from time to time
20140626 08:59:41 Updating service consul_server
20140626 08:59:41 Updating service ct
20140626 08:59:41 Configuration reload triggered
20140626 08:59:41 Waiting...
20140626 08:59:51 Waiting...
(...)
20140630 07:44:40 Waiting...
20140630 07:44:50 Waiting...