Created
September 30, 2014 03:42
-
-
Save ap4y/c6735917f8284f1ea516 to your computer and use it in GitHub Desktop.
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 | |
## | |
## Usage update_production service [image] | |
## | |
## Arguments: | |
## service: carnival-sidekiq. '-production' will be added automatically | |
## image: redis:latest. Can be empty, in this case image = service:latest | |
## | |
## | |
if [ -z $2 ]; then | |
$IMAGE = $1:latest | |
else | |
$IMAGE = $2 | |
fi | |
SERVICE = $1-production.service | |
# Check if there is a container with the same name in state Exited | |
CONTIANER = $(sudo docker ps -a | grep $SERVICE | grep 'Exited') | |
echo $CONTAINER | |
# Pull image | |
sudo docker pull $IMAGE | |
# Remove dead container | |
if [ -n $CONTAINER ]; then | |
sudo docker rm $SERVICE | |
fi | |
# Restart service | |
sudo systemctl restart $SERVICE | |
# Clean dangling images | |
sudo docker rmi $(sudo docker images -q -f 'dangling=true') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment