Files
template/customer/usr/local/bin/entry.sh
T

28 lines
1.0 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/dumb-init /bin/bash
# Ver: 1.5 by Endial Fang (endial@126.com)
#
# 容器入口脚本;当前脚本执行完毕时,使用默认用户执行镜像 CMD 定义的命令(默认为'/usr/local/bin/run.sh'
# 设置 shell 执行参数,可使用'-'(打开)'+'(关闭)控制。常用:
# -e: 命令执行错误则报错(errexit); -u: 变量未定义则报错(nounset); -x: 打印实际待执行的命令行; -o pipefail: 设置管道中命令遇到失败则报错
set -euo pipefail
. /colovu/lib/libcommon.sh # 加载通用函数库
LOG_I "** Processing entry.sh **"
# 检测是否仅打印帮助信息(CMD 命令第一个参数以'-'起始)
[[ "${1:0:1}" == '-' ]] && "${APP_EXEC:-${APP_NAME:-/bin/bash}}" "$@" || exit
# 判断是否为 root 用户
if [[ "$(id -u)" == '0' ]]; then
print_image_welcome
/usr/local/bin/setup.sh
# 使用非 root 用户执行 CMD 命令,并替换当前进程
exec gosu "${APP_USER}" "$@"
fi
LOG_I "Start container with command: $@"
# 执行'$@'定义的指令,并替换当前进程
exec "$@"