#!/bin/bashset -euo pipefail
# Check if the the user has invoked the image with flags.# eg. "apm-server -c apm-server.yml"if[[ -z $1]]||[[${1:0:1}=='-']];thenexec apm-server "$@"else# They may be looking for a Beat subcommand, like "apm-server setup".
subcommands=$(apm-server help \
|awk'BEGIN {RS=""; FS="\n"} /Available Commands:/' \
|awk'/^\s+/ {print $1}')# If we _did_ get a subcommand, pass it to apm-server.for subcommand in$subcommands;doif[[$1==$subcommand]];thenexec apm-server "$@"fidonefi# If neither of those worked, then they have specified the binary they want, so# just do exactly as they say.exec"$@"
概述在docker的启动脚本中,我们经常可以看到有exec来启动执行命令,那这个到底有什么作用呢?我们来简单验证一下。#!/bin/bashset -euo pipefail# Check if the the user has invoked the image with flags.# eg. "apm-server -c apm-server.yml"if [[ -z $1 ]] || [[ ${1:0:1} == '-' ]] ; then exec apm-server "