-
Notifications
You must be signed in to change notification settings - Fork 590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docker-compose: Bugfix: #1598
docker-compose: Bugfix: #1598
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#!/bin/sh | ||
# Version: 1.1.2 | ||
# Date: 2020-06-24 | ||
|
||
# Version: 1.1.3 | ||
# Date: 2021-09-24 | ||
# | ||
# Resource script for running docker-compose | ||
# | ||
|
@@ -35,7 +36,7 @@ | |
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs | ||
|
||
# Defaults | ||
OCF_RESKEY_binpath_default=/usr/bin/docker-compose | ||
OCF_RESKEY_binpath_default=/usr/local/bin/docker-compose | ||
OCF_RESKEY_ymlfile_default=docker-compose.yml | ||
: ${OCF_RESKEY_binpath=${OCF_RESKEY_binpath_default}} | ||
: ${OCF_RESKEY_ymlfile=${OCF_RESKEY_ymlfile_default}} | ||
|
@@ -100,7 +101,7 @@ For example, "docker-compose.yml" | |
|
||
<actions> | ||
<action name="start" timeout="240s"/> | ||
<action name="stop" timeout="20s"/> | ||
<action name="stop" timeout="60s"/> | ||
<action name="monitor" depth="0" timeout="10s" interval="60s" /> | ||
<action name="validate-all" timeout="5s" /> | ||
<action name="meta-data" timeout="5s"/> | ||
|
@@ -122,25 +123,37 @@ YML="$OCF_RESKEY_ymlfile" | |
|
||
docker_kill() | ||
{ | ||
for i in $(docker ps --all | awk -e '$NF ~ /\<'"${PRE}"'_.*_[0-9]+\>/ {print $1}'); do | ||
docker kill $i >/dev/null 2>&1 | ||
docker rm $i >/dev/null 2>&1 || RTV=false | ||
done | ||
if [ "$RTV" = false ]; then | ||
ocf_log err "failed to kill docker" | ||
return $OCF_ERR_GENERIC | ||
cd /tmp | ||
if systemctl status docker | grep -q 'Active: active (running)'; then | ||
for i in $(docker ps --all | awk -e '$NF ~ /\<'"${PRE}"'[-_]/ {print $1}'); do | ||
docker kill $i >/dev/null 2>&1 | ||
docker rm $i >/dev/null 2>&1 || RTV=false | ||
done | ||
if [ "$RTV" = false ]; then | ||
ocf_log err "failed to kill docker" | ||
return $OCF_ERR_GENERIC | ||
else | ||
RUN=false | ||
fi | ||
else | ||
RUN=false | ||
fi | ||
} | ||
|
||
docker_compose_status() | ||
{ | ||
# return if docker service is not running | ||
systemctl status docker | grep -q 'Active: active (running)' || { | ||
ocf_log info "docker daemon is not running." | ||
return $OCF_NOT_RUNNING | ||
} | ||
# use docker-compose ps if YML found, otherwise try docker ps and kill containers | ||
if [ -r "$DIR/$YML" ]; then | ||
|
||
DKPS=$(cd $DIR; $COMMAND ps -q) | ||
STAT_MSG=$(docker ps --no-trunc | grep -E $(echo "$DKPS" | tr '\n' '|') | expand) | ||
DKPS=$(cd $DIR; $COMMAND ps -q 2>/dev/null) | ||
cd /tmp | ||
STAT_MSG=$(docker ps --no-trunc | expand) | ||
PSTAT_MSG=$(echo "$STAT_MSG" | grep -E $(echo "$DKPS" | tr '\n' '|' | sed 's/|$//') 2>/dev/null) | ||
LNWTH=$(echo "$STAT_MSG" | head -n1 | wc -c) | ||
STATEPOS=$(echo "$STAT_MSG" | head -n1 | egrep -o 'STATUS.*$' | wc -c) | ||
OFFSET=$(($LNWTH-$STATEPOS+1)) | ||
|
@@ -150,7 +163,7 @@ docker_compose_status() | |
else | ||
PSNU=0 | ||
fi | ||
UPNU=$(echo "$STAT_MSG" | cut -c ${OFFSET}- | awk '{print $1}' | grep -w '^Up' | wc -l) | ||
UPNU=$(echo "$PSTAT_MSG" | cut -c ${OFFSET}- | awk '{print $1}' | grep -w '^Up' | wc -l) | ||
|
||
if [ "${PSNU:-0}" -ne 0 ]; then | ||
if [ ${UPNU:-0} -eq 0 ]; then | ||
|
@@ -167,7 +180,7 @@ docker_compose_status() | |
RUN=false | ||
fi | ||
else | ||
STAT_MSG=$(docker ps --all | awk -e '$NF ~ /\<'"$PRE"'_.*_[0-9]+\>/ {print $1}') | ||
STAT_MSG=$(docker ps --all | awk -e '$NF ~ /\<'"${PRE}"'[-_]/ {print $1}') | ||
if [ -z "$STAT_MSG" ]; then | ||
RUN=false | ||
else | ||
|
@@ -183,19 +196,25 @@ docker_compose_status() | |
|
||
docker_compose_start() | ||
{ | ||
|
||
sleep 5 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You shouldnt need to sleep here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, agree. I am still working on it... it could be improved in the future version. |
||
|
||
docker_compose_validate_all | ||
docker_compose_status >/dev/null 2>&1 | ||
retVal=$? | ||
# return success if docker service is running | ||
[ $retVal -eq $OCF_SUCCESS ] && exit $OCF_SUCCESS | ||
|
||
sleep 10 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you need to wait here you need to add a loop checking every 1-2s (and fails when Pacemaker timeouts) to avoid waiting too much in general, and also work for cases where it takes more than 10s. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, agree. I am still working on it... it could be improved in the future version. |
||
cd $DIR | ||
$COMMAND up -d || { | ||
ocf_log err "Error. docker-compose returned error $?." | ||
cd /tmp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You shouldnt need to run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
exit $OCF_ERR_GENERIC | ||
} | ||
|
||
ocf_log info "docker service started." | ||
cd /tmp | ||
exit $OCF_SUCCESS | ||
} | ||
|
||
|
@@ -209,6 +228,7 @@ docker_compose_stop() | |
ocf_log err "Error on shutting down docker service, try docker kill..." | ||
RUN_KILL=true | ||
} | ||
cd /tmp | ||
else | ||
RUN_KILL=true | ||
fi | ||
|
@@ -220,6 +240,7 @@ docker_compose_stop() | |
} | ||
fi | ||
ocf_log info "docker service stopped." | ||
cd /tmp | ||
exit $OCF_SUCCESS | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldnt change the default path for it. The setting is there so you can set what the path is on your system when it's not in the default location.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to change the default path aligned to Ubuntu distribution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to use get_release_id() for that (see ocf-distro file for logic).