Skip to content

Commit

Permalink
[cli] - Add check for exec on file system (#4326)
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Jewell <tjewell@codenvy.com>
* exec check
* add --follow
  • Loading branch information
Tyler Jewell authored Mar 7, 2017
1 parent 93d4474 commit 37275d3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 12 deletions.
23 changes: 21 additions & 2 deletions dockerfiles/base/scripts/base/commands/cmd_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ help_cmd_start() {
text "Starts ${CHE_MINI_PRODUCT_NAME} and verifies its operation\n"
text "\n"
text "PARAMETERS:\n"
text " --follow Displays server logs to console and blocks until user interrupts\n"
text " --force Uses 'docker rmi' and 'docker pull' to forcibly retrieve latest images\n"
text " --no-force Updates images if matching tag not found in local cache\n"
text " --pull Uses 'docker pull' to check for new remote versions of images\n"
Expand All @@ -29,6 +30,7 @@ pre_cmd_start() {
CHE_SKIP_CONFIG=false
CHE_SKIP_PREFLIGHT=false
CHE_SKIP_POSTFLIGHT=false
CHE_FOLLOW_LOGS=false
FORCE_UPDATE="--no-force"

while [ $# -gt 0 ]; do
Expand All @@ -42,6 +44,9 @@ pre_cmd_start() {
--skip:postflight)
CHE_SKIP_POSTFLIGHT=true
shift ;;
--follow)
CHE_FOLLOW_LOGS=true
shift ;;
--force)
FORCE_UPDATE="--force"
shift ;;
Expand Down Expand Up @@ -226,8 +231,14 @@ wait_until_booted() {

# CHE-3546 - if in development mode, then display the che server logs to STDOUT
# automatically kill the streaming of the log output when the server is booted
if debug_server; then
docker logs -f ${CHE_CONTAINER_NAME} &
if debug_server || follow_logs; then
DOCKER_LOGS_COMMAND="docker logs -f ${CHE_CONTAINER_NAME}"

if debug_server; then
DOCKER_LOGS_COMMAND+=" &"
fi

eval $DOCKER_LOGS_COMMAND
LOG_PID=$!
else
info "start" "Server logs at \"docker logs -f ${CHE_CONTAINER_NAME}\""
Expand Down Expand Up @@ -309,3 +320,11 @@ skip_postflight() {
return 1
fi
}

follow_logs() {
if [ "${CHE_FOLLOW_LOGS}" = "true" ]; then
return 0
else
return 1
fi
}
36 changes: 27 additions & 9 deletions dockerfiles/base/scripts/base/startup_02_pre_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,9 @@ init_check_mounts() {
fi

# Verify that we can write to the host file system from the container
check_host_volume_mount
if ! is_fast; then
check_host_volume_mount
fi

DEFAULT_CHE_CONFIG="${DATA_MOUNT}"
DEFAULT_CHE_INSTANCE="${DATA_MOUNT}"/instance
Expand Down Expand Up @@ -642,32 +644,48 @@ check_host_volume_mount() {
warning "Boot2docker detected - ensure :/data is mounted to %userprofile%"
fi

if file_system_writable "${CHE_CONTAINER_ROOT}/test"; then
delete_file_system_test "${CHE_CONTAINER_ROOT}/test"
else
error "Unable to write files to your host"
add_file_system_test "${CHE_CONTAINER_ROOT}/test"

if ! file_system_writable "${CHE_CONTAINER_ROOT}/test" ||
! file_system_executable "${CHE_CONTAINER_ROOT}/test"; then
error "Unable to write or execute files on your host."
error "Have you enabled Docker to allow mounting host directories?"
error "Did you give our CLI rights to create files on your host?"
error "Did you give our CLI rights to create + exec files on your host?"
delete_file_system_test "${CHE_CONTAINER_ROOT}/test"
return 2;
fi

delete_file_system_test "${CHE_CONTAINER_ROOT}/test"
}

file_system_writable() {
echo 'test' > "${1}"
add_file_system_test() {
echo '#!/bin/sh' > "${1}"
echo 'echo hi' >> "${1}"
chmod +x "${1}" > /dev/null
}

file_system_writable() {
if [[ -f "${1}" ]]; then
return 0
else
return 1
fi
}

file_system_executable() {
EXEC_OUTPUT=$(bash "${1}")
if [ $EXEC_OUTPUT = "hi" ]; then
return 0
else
return 1
fi
}

delete_file_system_test() {
rm -rf $1 > /dev/null 2>&1
}

is_boot2docker() {
# debug $FUNCNAME
if uname -r | grep -q 'boot2docker'; then
return 0
else
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/base/scripts/base/startup_05_pre_exec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ cli_parse () {
rmi|upgrade|version|ssh|sync|action|test|compile|dir|help)
;;
*)
error "You passed an unknown command."
error "You passed an unknown command: $1"
usage
return 2
;;
Expand Down

0 comments on commit 37275d3

Please sign in to comment.