Skip to content

Instantly share code, notes, and snippets.

@krohne
Last active January 11, 2019 20:21
Show Gist options
  • Save krohne/dabf4cdddbd412c85aa9c4661cbd03f0 to your computer and use it in GitHub Desktop.
Save krohne/dabf4cdddbd412c85aa9c4661cbd03f0 to your computer and use it in GitHub Desktop.
Restart remote platform container, usually because a source file or logging level has been changed
#!/bin/bash
# Your bastion username should be in ~/.ssh/config
# platform [container]
# preprod tripnotificationagent
export platform=$1
export container=$2
if [ -z ${container} ]; then export container=$(grep '"name":\s*"\w*",' $PWD/package.json | awk -F '"' '{ print $4 }'); fi
echo "Container: $container"
if [ -z ${container} ];
then
echo "No container set"
else
ssh $platform /bin/bash << EOF
cd /home/ubuntu
docker-compose stop $container
docker-compose up -d $container
EOF
fi
@krohne
Copy link
Author

krohne commented Jan 11, 2019

If run from the repository of the container to be restarted, no need to set container. The script will extract the container from package.json. For example:

/Volumes/Routematch/Git/mod-service-node-trip-notification-agent$ ~/restart_platform_container.sh gregkrohne preprod
Container: tripnotificationagent

@krohne
Copy link
Author

krohne commented Jan 11, 2019

Added the check for missing container at the end, because it turns out that if container is blank, the script will restart all of the containers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment