#cloud-config
"coreos":
  "units":
  - "command": |-
      stop
    "mask": !!bool |-
      true
    "name": |-
      etcd.service
  - "command": |-
      stop
    "mask": !!bool |-
      true
    "name": |-
      update-engine.service
  - "command": |-
      stop
    "mask": !!bool |-
      true
    "name": |-
      locksmithd.service
  - "command": |-
      stop
    "name": |-
      systemd-resolved.service
  - "command": |-
      start
    "content": |
      [Unit]
      Before=dcos.target
      [Service]
      Type=oneshot
      StandardOutput=journal+console
      StandardError=journal+console
      ExecStartPre=/usr/bin/mkdir -p /etc/profile.d
      ExecStart=/usr/bin/ln -sf /opt/mesosphere/environment.export /etc/profile.d/dcos.sh
    "name": |-
      dcos-link-env.service
  - "content": |
      [Unit]
      Description=Download the DCOS
      After=network-online.target
      Wants=network-online.target
      ConditionPathExists=!/opt/mesosphere/
      [Service]
      EnvironmentFile=/etc/mesosphere/setup-flags/bootstrap-id
      Type=oneshot
      StandardOutput=journal+console
      StandardError=journal+console
      ExecStartPre=/usr/bin/curl --fail --retry 20 --continue-at - --location --silent --show-error --verbose --output /tmp/bootstrap.tar.xz https://downloads.mesosphere.com/dcos/stable/bootstrap/$${BOOTSTRAP_ID}.bootstrap.tar.xz
      ExecStartPre=/usr/bin/mkdir -p /opt/mesosphere
      ExecStart=/usr/bin/tar -axf /tmp/bootstrap.tar.xz -C /opt/mesosphere
      ExecStartPost=-/usr/bin/rm -f /tmp/bootstrap.tar.xz
    "name": |-
      dcos-download.service
  - "command": |-
      start
    "content": |-
      [Unit]
      Description=Prep the Pkgpanda working directories for this host.
      Requires=dcos-download.service
      After=dcos-download.service
      [Service]
      Type=oneshot
      StandardOutput=journal+console
      StandardError=journal+console
      EnvironmentFile=/opt/mesosphere/environment
      ExecStart=/opt/mesosphere/bin/pkgpanda setup --no-block-systemd
      [Install]
      WantedBy=multi-user.target
    "enable": !!bool |-
      true
    "name": |-
      dcos-setup.service
  - "content": |
      [Unit]
      Description=Backup of cassandra database

      [Service]
      Type=oneshot
      Environment=AWS_CONFIG_FILE=/home/core/.aws/config
      ExecStart=/home/core/cassandra-backup/backup-witan.sh
    "enable": !!bool |-
      true
    "name": |-
      backup.service
  - "command": |-
      start
    "content": |
      [Unit]
      Description=Run backup.service once a day at 5am

      [Timer]
      OnCalendar=*-*-* 05:00:00
    "enable": !!bool |-
      true
    "name": |-
      backup.timer
  "update":
    "reboot-strategy": |-
      off
"write_files":
- "content": |
    {
      "environment": {
        "PROVIDER": "aws"
      }
    }
  "path": |-
    /etc/mesosphere/setup-packages/dcos-provider-aws--setup/pkginfo.json
- "content": |
    AWS_REGION=${aws-region}
    AWS_STACK_ID=${cluster-id}
    AWS_STACK_NAME=${cluster-name}
    AWS_IAM_MASTER_ROLE_NAME=${master-role}
    AWS_IAM_SLAVE_ROLE_NAME=${slave-role}
    AWS_ACCESS_KEY_ID=${aws-access-key}
    AWS_SECRET_ACCESS_KEY=${aws-secret-access-key}
    ZOOKEEPER_CLUSTER_SIZE=${number-of-masters}
  "path": |-
    /etc/mesosphere/setup-packages/dcos-provider-aws--setup/etc/cloudenv
- "content": |
    MESOS_CLUSTER=${cluster-name}
  "path": |-
    /etc/mesosphere/setup-packages/dcos-provider-aws--setup/etc/mesos-master-provider
- "content": |
    EXHIBITOR_BACKEND=AWS_S3
    AWS_REGION=${aws-region}
    AWS_S3_BUCKET=${exhibitor-s3-bucket}
    AWS_S3_PREFIX=${cluster-name}
  "path": |-
    /etc/mesosphere/setup-packages/dcos-provider-aws--setup/etc/exhibitor
- "content": |
    com.netflix.exhibitor.s3.access-key-id=${aws-access-key}
    com.netflix.exhibitor.s3.access-secret-key=${aws-secret-access-key}
  "path": |-
    /etc/mesosphere/setup-packages/dcos-provider-aws--setup/etc/exhibitor.properties
- "content": |
    MASTER_SOURCE=exhibitor
    EXHIBITOR_ADDRESS=${internal-lb-dns}
    RESOLVERS=${fallback-dns}
  "path": |-
    /etc/mesosphere/setup-packages/dcos-provider-aws--setup/etc/dns_config
- "content": |-
    ${cluster-id}
  "path": |-
    /etc/mesosphere/cluster-id
  "permissions": |-
    0644
- "content": |
    https://downloads.mesosphere.com/dcos/stable
  "owner": |-
    root
  "path": |-
    /etc/mesosphere/setup-flags/repository-url
  "permissions": !!int |-
    420
- "content": |
    BOOTSTRAP_ID=299269a7aa9e23a1edc94de3f2375356b2942af8
  "owner": |-
    root
  "path": |-
    /etc/mesosphere/setup-flags/bootstrap-id
  "permissions": !!int |-
    420
- "content": |-
    ["dcos-config--setup_7660c4e993820a3dea2c017b37c7eeb93151b1da", "dcos-detect-ip--setup_7660c4e993820a3dea2c017b37c7eeb93151b1da", "dcos-metadata--setup_7660c4e993820a3dea2c017b37c7eeb93151b1da"]
  "owner": |-
    root
  "path": |-
    /etc/mesosphere/setup-flags/cluster-packages.json
  "permissions": !!int |-
    420
- "content": ""
  "path": |-
    /etc/mesosphere/roles/slave
- "content": ""
  "path": |-
    /etc/mesosphere/roles/aws
- "content": |
    #!/bin/sh

    # necessary for java location
    export PATH=$PATH:/opt/mesosphere/bin
    CASSANDRA_DIR=$(ps -A -o command | grep CassandraDaemon | grep '/var/lib' | cut -d' ' -f1 | sed -e 's#/jre1.7.0.*##')
    CASSANDRA_DATA_DIR=$CASSANDRA_DIR/data/
    NODETOOL=$(find $CASSANDRA_DIR -name nodetool)
    AWS=$(find /opt/mesosphere -name aws)
    directory=$($NODETOOL snapshot witan | awk '/directory/{print $3}')

    # We assume it's worked if it tells us the directory
    if [ -z "${directory}" ]; then
       echo "Problem getting snapshot directory"
       exit 1;
    fi

    # We only want the snapshots dirs
    # For filters rationale see http://docs.aws.amazon.com/cli/latest/reference/s3/index.html#use-of-exclude-and-include-filters
    sudo -u core $AWS --profile backup s3 sync --exclude '*' --include '*/snapshots/*' ${CASSANDRA_DATA_DIR} s3://witan-cassandra-backup/$(hostname)/
  "path": |-
    /home/core/cassandra-backup/backup-witan.sh
  "permissions": |-
    0644
