Commit 9279b059 authored by Paul Desplanque's avatar Paul Desplanque

Better container management

parent 10212fe7
......@@ -16,6 +16,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Error in documentation
### Changed
- is-running is safer to use
- The stop command always tries to remove the container, whatever is-running says
## [1.2.0] - 2018-04-08
......
......@@ -9,7 +9,10 @@ function say_no {
service docker status &>/dev/null || say_no
docker ps | grep -q " $APP_NAME$"
[ $? -eq 0 ] || say_no
status=$(docker inspect -f='{{.State.Status}}' "$APP_NAME" 2>/dev/null)
[ "$status" == "running" ] && {
echo "yes"
exit
}
echo "yes"
say_no
......@@ -3,10 +3,18 @@ SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
APP_NAME=$(basename "$SELF_DIR")
[ $(. "$SELF_DIR"/is-running) == "yes" ] || {
docker inspect -f='{{.State.Status}}' "$APP_NAME" &>/dev/null
[ $? -ne 0 ] && {
echo "$APP_NAME is already stopped"
exit
}
}
docker stop $APP_NAME >/dev/null && \
docker rm $APP_NAME >/dev/null && \
echo "$APP_NAME stopped"
docker stop $APP_NAME >/dev/null
docker rm -f $APP_NAME >/dev/null && {
echo "$APP_NAME stopped"
exit
}
echo "Error while trying to remove $APP_NAME container" >&2
exit 1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment