Skip to content

Instantly share code, notes, and snippets.

@bahamat
bahamat / cmon.sh
Last active April 25, 2024 18:43
Shell script to pull CMON metrics from Joyent Triton (https://www.joyent.com/triton)
#!/bin/bash
# shellcheck disable=SC2154
if [[ -n "$TRACE" ]]; then
export PS4='[\D{%FT%TZ}] ${BASH_SOURCE}:${LINENO}: ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
set -o xtrace
fi
export PATH=/opt/pkg/bin:/opt/local/bin:/opt/custom/bin:$PATH
@bahamat
bahamat / shell_config.md
Last active March 15, 2023 02:42
How are various shells configured, and in which order?

ash & dash

login interactive files
N N
N Y $ENV
Y N /etc/profile, ~/.profile
Y Y /etc/profile, ~/.profile, $ENV

bash

@bahamat
bahamat / triton-update-all
Last active January 31, 2021 16:52
Script to update/upgrade all components of SDC/Triton
[root@headnode (barovia) ~]# cat /opt/custom/bin/update-all
#!/bin/bash
set -o errexit
set -o xtrace
imgadm vacuum -f
sdcadm update --all --just-images -y
sdcadm self-update --allow-major-update --latest
@bahamat
bahamat / no_compute_resources_available.md
Last active December 5, 2021 07:14
Diagnosing "No Compute Resources Available" messages in Triton.

No Compute Resources Available

This error is somewhat ambiguious because there is seemingly no indication which resource is exhausted.

Triton chooses compute nodes with a subcomponent called sdc-designation (also refered to as , DAPI). The full DAPI log for a provision job is embedded in the CNAPI log file and can be extracted with the workflow job uuid.

Note: The script below is no longer necessary because cnapi now includes /opt/smartdc/cnapi/bin/alloc-reasons.sh which does the same thing.

#!/bin/bash
@bahamat
bahamat / nginx_log_format_bunyan.conf
Last active September 14, 2016 08:12
nginx log_format bunyan
log_format bunyan '{'
'"name": "nginx/$nginx_version",'
'"hostname": "$hostname",'
'"pid": "$pid",'
'"level": 30,'
'"time": "$time_iso8601",'
'"v": 0,'
'"msg": "access",'
'"remoteAddress": "$remote_addr",'
@bahamat
bahamat / 00-illumos_SMF_manifests_for_CFengine.md
Last active November 11, 2015 17:49
illumos SMF manifests for Cfengine.

Download each file using the Raw link, or clone this gist then run the following commands:

svccfg import cf-serverd.xml
svccfg import cf-monitord.xml
svcdfg import cf-execd.xml

In your policy, cfe_internal/update/update_processes.cf should be updated accordingly to enable the SMF services instead of executing commands directly.

#!/bin/bash
# This little hack-job will grab credentials from a running openvpn process in Linux
# Keep in mind this won't work if the user used the --auth-nocache flag
grep rw-p /proc/$1/maps | sed -n 's/^\([0-9a-f]*\)-\([0-9a-f]*\) .*$/\1 \2/p' | while read start stop; do gdb --batch-silent --silent --pid $1 -ex "dump memory $1-$start-$stop.dump 0x$start 0x$stop"; done
echo "Your credentials should be listed below as username/password"
strings *.dump | grep -B2 KnOQ | grep -v KnOQ
rm *.dump --force
#!/bin/bash
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# Copyright (c) 2015, Brian Bennett <bahamat@digitalelf.net>
cn=$1; shift
action=$1; shift
@bahamat
bahamat / moved.md
Last active May 16, 2017 22:31
Update all components of SDC.
@bahamat
bahamat / pipasswd
Last active January 5, 2017 19:45
Find the SmartDataCenter default root password for any installed platform image.
#!/bin/bash
if (( UID > 0 )); then
echo "You must elevate privileges."
exit 1
fi
usbkey_status=$(/opt/smartdc/bin/sdc-usbkey status)
passwd_file=/mnt/usbkey/private/root.password.$1