Skip to content

Instantly share code, notes, and snippets.

View portante's full-sized avatar

Peter Portante portante

View GitHub Profile
@portante
portante / blog_bash_sighands_NOT.md
Last active June 14, 2021 18:10
Poor Man's Blog: "When do bash signal handlers NOT work?"

"When do bash signal handlers NOT work?"

March 19th, 2019

Just in case somebody else runs into this frustrating situation, (at least on RHEL 7) bash shell scripts trying to catch SIGINT do not work when the signal is sent to the process from another pid and your bash script is running a non-shell built-in.

Yesterday I was attempting to mock out a linux command to verify the behavior of a shell script I wrote. The goal was to be able to test the shell script's behavior without actually invoking the particular linux command (see pbench PR #1108). One feature of the script being tested was sending a SIGINT to another process, being sure the script had properly identified the correct process.

There is a nice blog about how to write signal handlers for bash, well worth the read [1]. Using that blog, I came up with a very simple mock command shell script:

@portante
portante / are-shards-balanced.py
Last active September 13, 2019 03:10
A simple script to generate a report of Elasticsearch shard usage (from _cat/shards/?v&bytes=b) to see which shards of an index are not evenly spread across the cluster.
#!/usr/bin/env python2
# A script to generate a report of Elasticsearch shard usage
# (from _cat/shards?v&bytes=b) to see which shards of an index
# are not evenly spread across the cluster, and for a set of
# hard-coded date patterns, which date patterns are not spread
# evenly across the cluster.
#
# E.g.
# $ curl -X GET http://localhost:9200/_cat/shards?v\&bytes=b -o shards.lis
@portante
portante / merge_vs_rebase.md
Created September 11, 2018 10:53
Git merge vs Git rebase

What to do about so many empty merge commits?

I think it has to do with a branch "merging" up to master by using git merge/pull instead of using git rebase.

If you make a change in a branch from a particular commit ID on master, and then master moves ahead, and you use git merge to update that branch, git gratuitously creates "merge commits" which cover the changes made to automatically merge the new changes since your change was made on master.

In contrast, a git rebase (assuming you have properly setup remote tracking with git branch --set-upstream-to=...) takes your commits (really the diffs those commits represent) and re-applies it to the latest on the tracking branch adjusting your commits to work on top of that rebase.

For example, let's say we have master with commits A, B, and C:

@portante
portante / code.bash
Last active August 16, 2018 02:24
The record_iteration functions from pbench-uperf and pbench-user-benchmark for comparison purposes while debugging how iteration recording is handled in pbench.
# August 15th, 2018
# from pbench-uperf
function record_iteration {
local count=$1
local protocol=$2
local test_type=$3
local message_size=$4
local instance=$5
local iteration=$6
@portante
portante / errors.log
Created August 13, 2018 22:30
Python3 double exceptions from elasticsearch1 logging output
! Traceback (most recent call last):
! File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 387, in _make_request
! six.raise_from(e, None)
! File "<string>", line 2, in raise_from
! File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 383, in _make_request
! httplib_response = conn.getresponse()
! File "/opt/rh/rh-python36/root/usr/lib64/python3.6/http/client.py", line 1331, in getresponse
! response.begin()
! File "/opt/rh/rh-python36/root/usr/lib64/python3.6/http/client.py", line 297, in begin
! version, status, reason = self._read_status()
@portante
portante / sum-es-indices.py
Last active January 21, 2021 21:10
A script to generate a report of Elasticsearch index usage (from _cat/indices?v&bytes=b) by prefix for a set of known date suffixes.
#!/usr/bin/env python2
# A script to generate a report of Elasticsearch index usage
# (from _cat/indices?v&bytes=b) by prefix for a set of known
# date suffixes.
#
# E.g.
# $ curl -X GET http://localhost:9200/_cat/indices?v\&bytes=b -o indices.lis
# $ ./sum-es-indices.py indices.lis
#
@portante
portante / pending-tasks.sh
Created April 20, 2018 18:07
A simple script to fetch the list of pending tasks from Elasticsearch as deployed in OCP Aggregated Logging.
#!/bin/bash
ES_URL='https://localhost:9200'
curl_get='curl -s -X GET --cacert /etc/elasticsearch/secret/admin-ca --cert /etc/elasticsearch/secret/admin-cert --key /etc/elasticsearch/secret/admin-key'
date
$curl_get $ES_URL/_cluster/pending_tasks?pretty
@portante
portante / put-queue-size.sh
Created April 10, 2018 12:00
A simple script to change the bulk queue size for ES in OpenShift.
#!/bin/bash
ES_URL='https://localhost:9200'
curl_put='curl -s -X PUT --cacert /etc/elasticsearch/secret/admin-ca --cert /etc/elasticsearch/secret/admin-cert --key /etc/elasticsearch/secret/admin-key'
$curl_put $ES_URL/_cluster/settings?pretty -d "{\"persistent\" : {\"threadpool.bulk.queue_size\" : $1}}"
@portante
portante / get-fluentd-running
Last active December 4, 2021 13:47
A script to help get fluentd pods running on all labeled nodes of an OpenShift cluster; we need this because Kube currently does not support priority or preemption which we could use to ensure fluentd are always scheduled and run on properly labeled nodes.
#!/bin/bash
function finish {
rm -rf $TMPDIR
}
trap finish EXIT
TMPDIR=$(mktemp -d)
oc get nodes -o name > $TMPDIR/all-nodes
oc get nodes -o name -l logging-infra-fluentd=true > $TMPDIR/labeled-nodes
@portante
portante / exists-index.sh
Last active March 22, 2018 15:29
Check if an index exists in OpenShift ES aggregated logging.
#!/bin/bash
ES_URL='https://localhost:9200'
curl_head='curl -w %{http_code}\n -s -X HEAD --cacert /etc/elasticsearch/secret/admin-ca --cert /etc/elasticsearch/secret/admin-cert --key /etc/elasticsearch/secret/admin-key'
$curl_head $ES_URL/${1}?pretty=true