Skip to content

Instantly share code, notes, and snippets.

View jwreagor's full-sized avatar

J R jwreagor

  • New Gillington, WI
View GitHub Profile
@jwreagor
jwreagor / NOTES.md
Last active November 29, 2017 03:05
Example ContainerPilot 3 Config

Walk through

  • CONSUL is the address of our Consul cluster. This defaults to just "consul" if used by local Docker linked containers.

  • Only if the env var CONSUL_AGENT is available do we want to run the consul-agent job. This runs the consul agent process inside our container which our containerpilot process will use to communicate with our external Consul cluster. We also want consul-agent to have a health check as well.

  • Run the preStart job. This can be used to preconfigure the "main" service of a container like setting an IP address inside a configuration file.

  • Caveat: If we're given CONSUL_AGENT than our preStart will run after the consul-agent job is healthy.

DEBU[0000] loaded config: {"Discovery":{},"LogConfig":{"level":"DEBUG","format":"text","output":"stdout"},"StopTimeout":5,"Jobs":[{"Name":"test-repeats","Exec":"./test-sleep.sh","Port":0,"Interfaces":null,"Tags":null,"ConsulExtras":null,"Health":null,"ExecTimeout":"never","Restarts":null,"StopTimeout":"","When":{"Frequency":"12s","Source":"","Once":"","Each":"","Timeout":""},"Logging":null}],"Watches":null,"Telemetry":null,"Control":{"SocketPath":"/tmp/cp-single.socket"}}
DEBU[0000] control: initialized router for control server
DEBU[0000] control: listening to /tmp/cp-single.socket
DEBU[0000] event: {Startup global}
DEBU[0000] test-repeats.Run start
INFO[0000] control: serving at /tmp/cp-single.socket
INFO[0000] Going to sleep for 10s job=test-repeats pid=26574
INFO[0000] Tue, 21 Nov 2017 11:30:48 -0500 job=test-repeats pid=26574
INFO[0010] Tue, 21 Nov 2017 11:30:58 -0500 job=test-repeats pid=26574
DEBU[0010] test-repeats exited without error
=== RUN TestFoo_bar
bootstrap = true: do not enable unless necessary
==> Starting Consul agent...
==> Consul agent running!
Version: 'v1.0.0'
Node ID: 'd4afaaf6-c5fb-ac84-746f-9971f07e465d'
Node name: 'node-d4afaaf6-c5fb-ac84-746f-9971f07e465d'
Datacenter: 'dc1' (Segment: '<all>')
Server: true (Bootstrap: true)
Client Addr: [127.0.0.1] (HTTP: 10002, HTTPS: 10003, DNS: 10001)
@jwreagor
jwreagor / Dockerfile
Last active November 10, 2017 03:48
Example of how ContainerPilot handles jobs that continue running past their interval setting
FROM alpine:latest
RUN apk update && \
apk add curl bash
# Install ContainerPilot
ENV CONTAINERPILOT_VER=3.5.1
ENV CONTAINERPILOT=/etc/containerpilot.json5
RUN export CONTAINERPILOT_CHECKSUM=7ee8e59588b6b593325930b0dc18d01f666031d7 \
{
consul: "consul:8500",
logging: {
level: "DEBUG",
format: "text"
},
jobs: [
{
name: "test-thing",
exec: "tail -f"
*[f-signal-event][tzu][containerpilot]$ docker logs -f cpnew
time="2017-10-18T04:16:17Z" level=debug msg="loaded config: {"Discovery":{},"LogConfig":{"level":"DEBUG","format":"text","output":"stdout"},"StopTimeout":5,"Jobs":[{"Name":"on-sighup","Exec":"echo 'on-sighup job fired on SIGHUP'","Port":0,"Interfaces":null,"Tags":null,"ConsulExtras":null,"Health":null,"ExecTimeout":"","Restarts":null,"StopTimeout":"","When":{"Frequency":"","Source":"SIGHUP","Once":"","Each":"","Timeout":""},"Logging":null},{"Name":"on-sigusr2","Exec":"echo 'on-sigusr2 job fired on SIGUSR2'","Port":0,"Interfaces":null,"Tags":null,"ConsulExtras":null,"Health":null,"ExecTimeout":"","Restarts":null,"StopTimeout":"","When":{"Frequency":"","Source":"SIGUSR2","Once":"","Each":"","Timeout":""},"Logging":null}],"Watches":null,"Telemetry":null,"Control":{"SocketPath":"/var/run/containerpilot.socket"}}"
time="2017-10-18T04:16:17Z" level=debug msg="control: initialized router for control server"
time="2017-10-18T04:16:17Z" level=debug msg="cont
{
consul: "consul:8500",
logging: { level: "INFO" },
jobs: [
{
name: "job1",
exec: "tail -F"
}
]
}
@jwreagor
jwreagor / containerpilot.json5
Created October 18, 2017 03:51
debugging a possible memory leak
{
consul: "consul:8500",
jobs: [
{
name: "pjob",
port: 8080,
exec: "/bin/pjob start",
restarts: "unlimited",
health: {
exec: "curl --fail -s http://127.0.0.1:8080",
if opts.LogFile != "" {
logFp, err := os.OpenFile(opts.LogFile, os.O_WRONLY | os.O_APPEND | os.O_CREATE, 0600)
checkError(fmt.Sprintf("error opening %s", opts.LogFile), err)
defer logFp.Close()
// ensure panic output goes to log file
syscall.Dup2(int(logFp.Fd()), 1)
syscall.Dup2(int(logFp.Fd()), 2)
@jwreagor
jwreagor / GNUmakefile
Created October 6, 2017 03:53
Manta policy example
# Create backup user/policies (usage: make manta [email protected] PASSWORD=pwd)
# -------------------------------------------------------
# Create user and policies for backups
# Requires SDC_ACCOUNT to be set
# usage:
# make manta [email protected] PASSWORD=strongpassword
#
## Create backup user and policies
manta:
$(call check_var, EMAIL PASSWORD SDC_ACCOUNT, \