Last active
January 11, 2019 20:21
-
-
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
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
#!/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 |
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
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: