Skip to content

Instantly share code, notes, and snippets.

{
"title": "Cisco ASA",
"services": {
"query": {
"list": {
"0": {
"query": "*",
"alias": "",
"color": "#7EB26D",
"id": 0,
nginx/
!nginx/.gitkeep
!nginx/logs/.gitkeep
src/
tmp/

Boostrapping Salt on Linux EC2 with Cloud-Init

Salt is a great tool for remote execution and configuration management, however you will still need to bootstrap the daemon when spinning up a new node. One option is to create and save a custom AMI, but this creates another resource to maintain and document.

A better method for Linux machines uses Canonical's CloudInit to run a bootstrap script during an EC2 Instance initialization. Cloud-init takes the user_data string passed into a new AWS instance and runs it in a manner similar to rc.local. The bootstrap script needs to:

  1. Install Salt with dependencies
  2. Point the minion to the master
# salt-minion.conf
description "salt-minion upstart daemon"
author "Jeff Bauer <jbauer@rubic.com>"
# copy this file to /etc/init
start on (net-device-up and local-filesystems)
stop on shutdown
expect fork
require "cjson"
local util = require("util")
-- https://github.com/mozilla-services/lua_sandbox/blob/master/modules/util.lua
local message = {
Type = "IGNORE",
Fields = {}
}
// define these shard spaces
shardSpaces = [
{name: "raw", retention: "4h"},
{name: "week", retention: "7d"},
{name: "month", retention: "30d"},
{name: "year", retention: "365d"},
{name: "keep", retention: "inf"}
]
// apply these rules for mapping data to shard spaces
[hekad]
maxprocs = 2
base_dir = "/tmp/cache"
pid_file = "/tmp/hekad.pid"
share_dir = "/usr/share/heka"
[log1]
type = "LogstreamerInput"
log_directory = "/var/log/"
file_match = 'yum\.log'
supervisor:
pkg.latest:
- skip_suggestions: True
- refresh: False
service.running:
- enable: True
- reload: True
- watch: [ file: supervisor ]
file.managed:
- name: /etc/supervisord.conf

Go here for the latest + some code.

numbat

An alerting engine for a metrics & monitoring system.

This is the same approach I wanted in my initial spike, only instead of writing a custom collector & using an existing alerting engine (riemann), I'm proposing using an existing collector (hekad) and writing the alerting engine.

The system

Zero downtime deploys with gunicorn

Below are the actual files we use in one of our latest applications at Agora Games to achieve zero downtime deploys with gunicorn. I hope these files and notes help. I am happy to update these files or these notes if there are comments/questions. YMMV (of course).

Salient points for each file:

  • gunicorn.py: The pre_fork function looks for gunicorn's old PID file in the proper file and sends the proper QUIT signal to the old process once the new process is running.
  • sv-gunicorn-run.jinja: This is the runit template we use in our Salt-managed infrastructure for handling the application process management. You could just as easily convert this to a non-templatized version.