This repository has been archived by the owner on Mar 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates to make the sidecare do all the things (#5)
- Loading branch information
1 parent
601f42b
commit d655e5a
Showing
12 changed files
with
110 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# shellcheck shell=bash | ||
|
||
dotenv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash | ||
|
||
ECS_CLUSTER=$(curl -s http://localhost:51678/v1/metadata | jq -r .Cluster) | ||
if [ -z "$ECS_CLUSTER" ]; then | ||
ECS_CLUSTER="default" | ||
fi | ||
DOCKER_ID=$(awk -F/ '{ print $NF }' /proc/1/cpuset) | ||
BACKUP_INTERVAL=${1:-3600} | ||
|
||
_SERVICE=$(cat <<EOT | ||
{ | ||
"service": { | ||
"name": "${ECS_CLUSTER}", | ||
"address": "", | ||
"tags": [ | ||
"backup" | ||
], | ||
"checks": [ | ||
{ | ||
"id": "consul-backup-job", | ||
"name": "Consul Backups", | ||
"notes": "Job that run to create a consul snapshot and backup to s3", | ||
"docker_container_id": "${DOCKER_ID}", | ||
"shell": "/bin/bash", | ||
"args": ["/usr/local/bin/backup.sh"], | ||
"interval": "${BACKUP_INTERVAL}s", | ||
"status": "passing" | ||
} | ||
] | ||
} | ||
} | ||
EOT | ||
) | ||
|
||
echo ${_SERVICE} | ||
|
||
|
||
|
||
#{ | ||
# "service": { | ||
# "name": "ConsulBackup", | ||
# "checks": [ | ||
# { | ||
# "script": "/usr/local/bin/consul-backup.sh", | ||
# "status": "passing", | ||
# "interval": "3600s" | ||
# } | ||
# ] | ||
# } | ||
#} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/sh | ||
|
||
: ${S3_BUCKET} | ||
CONSUL_HTTP_ADDR="http://$(dudewheresmy hostip):8500" | ||
export CONSUL_HTTP_ADDR | ||
DC=$(curl -s ${CONSUL_HTTP_ADDR}/v1/catalog/datacenters | jq -r .[]) | ||
FILE="/tmp/$(hostname).snap" | ||
|
||
if [ ${S3_BUCKET} ]; then | ||
consul snapshot save $FILE | ||
/usr/bin/aws s3 mv ${FILE} s3://${S3_BUCKET}/${DC}/consul/ | ||
else | ||
echo "S3_BUCKET is not set, consul-backup.sh is disabled." | ||
exit 0 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/sh | ||
# shellcheck shell=sh | ||
# We probably want to replace this with something that eats json and do this in a non-horrible way | ||
|
||
sleep 10 | ||
/usr/local/bin/instance-status.sh | ||
|
||
RC=$? | ||
|
||
if [ $RC = 255 ]; then | ||
sleep 90 | ||
/bin/consul maint -enable | ||
/bin/consul leave | ||
else | ||
echo InstanceStatus is ok | ||
exit 0 | ||
fi |