{
  consul: "localhost:8500",
  logging: {
    level: "INFO",
    format: "default",
    output: "stdout"
  },
  jobs: [
    {
      name: "app",
      exec: "/bin/app",
      restarts: "unlimited",
      port: 80,
      when: {
        // we want to start this job when the "setup" job has exited
        // with success but give up after 60 sec
        source: "setup",
        once: "exitSuccess",
        timeout: "60s"
      },
      health: {
        exec: "/usr/bin/curl --fail -s -o /dev/null http://localhost/app",
        interval: 5,
        tll: 10,
        timeout: "5s",
      },
      tags: [
        "app",
        "prod"
      ],
      interfaces: [
        "eth0",
        "eth1[1]",
        "192.168.0.0/16",
        "2001:db8::/64",
        "eth2:inet",
        "eth2:inet6",
        "inet",
        "inet6",
        "static:192.168.1.100", // a trailing comma isn't an error!
        ]
    },
    {
      // we can create a chain of "setup" events by having
      // jobs wait for other jobs to become healthy
      name: "setup",
      when: {
        source: "consul-agent",
        once: "healthy"
      },
      exec: "/usr/local/bin/preStart-script.sh",
      restart: "never"
    },
    {
      name: "preStop",
      when: {
        source: "app",
        once: "stopping"
      },
      exec: "/usr/local/bin/preStop-script.sh",
      restart: "never",
    },
    {
      name: "postStop",
      when: {
        source: "app",
        once: "stopped"
      },
      exec: "/usr/local/bin/postStop-script.sh",
    },
    {
      // a service that doesn't have a "when" field starts up on the
      // global "startup" event by default
      name: "consul-agent",
      // note we don't have a port here because we don't intend to
      // advertise one to the service discovery backend
      exec: "consul -agent -join consul",
      restart: "always"
    },
    {
      name: "consul-template",
      exec: ["consul-template", "-consul", "consul",
             "-template", "/tmp/template.ctmpl:/tmp/result"],
      restart: "always",
    },
    {
      name: "periodic-task1",
      exec: "/usr/local/bin/task.sh arg1",
      timeout: "100ms",
      when: {
        interval: "1500ms"
      }
    },
    {
      name: "reload-app",
      when: {
        source: "watch.app",
        each: "changed"
      },
      exec: "/usr/local/bin/reload-app.sh",
      timeout: "10s"
    },
    {
      name: "reload-nginx",
      when: {
        source: "watch.nginx",
        each: "changed"
      },
      exec: "/usr/local/bin/reload-nginx.sh",
      timeout: "30s"
    },
    {
      // this job will write metrics to our telemetry collector
      name: "sensor",
      exec: "/usr/local/bin/sensor.sh"
      when: {
        interval: "5s"
      }
    }
  ],
  watches: {
    {
      name: "app",
      interval: 10
    },
    {
      name: "nginx",
      interval: 30
    }
  },
  control: {
    socket: "/var/run/containerpilot.socket"
  },
  telemetry: {
    port: 9090,
    interfaces: "eth0"
    metrics: [
      {
        name: "metric_id"
        help: "help text"
        type: "counter"
      }
    ]
  }
}
==========================================================================================
{
consul: '{{ if .CONSUL_AGENT }}localhost{{ else }}{{ .CONSUL | default "consul"}}{{ end }}:8500',
logging: {
level: '{{ .LOG_LEVEL | default "INFO" }}'
},
jobs: [
{
name: "preStart",
exec: "python /usr/local/bin/manage.py",
{{ if .CONSUL_AGENT }}when: {
source: "consul-agent",
once: "healthy"
}{{ end }}
},
{
name: '{{ .SERVICE_NAME | default "mysql" }}',
exec: [
"mysqld",
"--console",
"--log-bin=mysql-bin",
"--log_slave_updates=ON",
"--gtid-mode=ON",
"--enforce-gtid-consistency=ON"
],
port: 3306,
when: {
source: "preStart",
once: "exitSuccess"
},
health: {
exec: "python /usr/local/bin/manage.py health",
interval: 5,
ttl: 25
}
},
{
name: "onChange",
exec: "python /usr/local/bin/manage.py on_change",
when: {
source:'watch.{{ .SERVICE_NAME | default "mysql" }}-primary' ,
each: "changed"
}
},
{
name: "snapshot-check",
exec: "python /usr/local/bin/manage.py snapshot_task",
timeout: "10m",
when: {
interval: "5m"
},
},
{{ if .CONSUL_AGENT }}{
name: "consul-agent",
restarts: "unlimited",
exec: [
"/usr/local/bin/consul", "agent",
"-data-dir=/data",
"-config-dir=/config"
],
health: {
exec: 'consul join {{ .CONSUL | default "consul"}}',
interval: 5,
ttl: 10
}
}{{ end }}
],
watches: [
{
name: '{{ .SERVICE_NAME | default "mysql" }}-primary',
interval: 10
}
]
}