diff --git a/.alias b/.alias new file mode 100644 index 0000000..3440b58 --- /dev/null +++ b/.alias @@ -0,0 +1,12 @@ +alias aix-docker='docker-compose -f $AIX_DOCKER_COMPOSER_FILE' +alias aix-docker-up='docker-compose -f $AIX_DOCKER_COMPOSER_FILE up --build -d' +alias aix-docker-down='docker-compose -f $AIX_DOCKER_COMPOSER_FILE down' +alias aix-docker-restart='docker-compose -f $AIX_DOCKER_COMPOSER_FILE restart' +alias aix-php73-base='docker-compose -f $AIX_DOCKER_COMPOSER_FILE exec php73 /bin/sh' +alias aix-php74-base='docker-compose -f $AIX_DOCKER_COMPOSER_FILE exec php74 /bin/sh' +alias aix-php81-base='docker-compose -f $AIX_DOCKER_COMPOSER_FILE exec php81 /bin/sh' +alias aix-redis-base='docker-compose -f $AIX_DOCKER_COMPOSER_FILE exec redis /bin/sh' +alias aix-nginx-base='docker-compose -f $AIX_DOCKER_COMPOSER_FILE exec openresty /bin/sh' +alias aix-elastic-base='docker-compose -f $AIX_DOCKER_COMPOSER_FILE exec elasticsearch /bin/sh' +alias aix-php81-supervisor='docker-compose -f $AIX_DOCKER_COMPOSER_FILE exec php81 supervisorctl' +alias aix-php73-supervisor='docker-compose -f $AIX_DOCKER_COMPOSER_FILE exec php81 supervisorctl' diff --git a/openresty/config/conf/nginx.conf b/openresty/config/conf/nginx.conf index 12f1854..2a07a9a 100644 --- a/openresty/config/conf/nginx.conf +++ b/openresty/config/conf/nginx.conf @@ -121,6 +121,11 @@ lua_shared_dict my_limit_req_store1 100m; return 200 'alive' ; } } + server { + listen 443; + server_name _; + return 444; + } ########################## vhost ############################# include vhost/*.conf; } diff --git a/start.sh b/start.sh index fdd45b4..0027abf 100644 --- a/start.sh +++ b/start.sh @@ -1,9 +1,37 @@ #/bin/sh +docker_path="/data/aix-docker" pushd /data +function print_error() { + RED='\033[0;31m' + NC='\033[0m' + + echo -e "${RED}[ERROR] $1${NC}" >&2 +} +function print_success() { + GREEN='\033[0;32m' + NC='\033[0m' + echo -e "${GREEN}[SUCCESS] $1${NC}" >&2 +} +if [ "$EUID" -ne 0 ]; then + print_error "Please running as root" +fi +if [ -e "/root/.aix_docker.lock" ]; then + print_error "Initialization has been performed!" + exit 1 +fi +if ! command -v jq >/dev/null 2>&1 ; then + if [ -f /etc/redhat-release ]; then + yum install -y jq + elif [ -f /etc/debian_version ]; then + apt-get install -y jq + else + print_error "Unsupported Linux distribution" + exit 1 +fi if ! command -v docker >/dev/null 2>&1 ; then wget --no-check-certificate https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/static/stable/x86_64/docker-20.10.9.tgz if [ $? -ne 0 ]; then - echo "Download docker failed" + print_error "Download docker failed" exit 1 fi tar -zxvf docker-20.10.9.tgz @@ -42,11 +70,38 @@ if ! command -v docker-compose >/dev/null 2>&1 ; then fi if ! command -v git > /dev/null 2>&1 ; then - echo '请安装Git' + print_error '请安装Git' return 1; fi -git clone https://opencode.jsaix.cn/chenc/aix-docker.git /data/aix-docker -cd /data/aix-docker -docker-compose up --build -d \ No newline at end of file +if [ ! -d "$docker_path" ]; then + git clone https://opencode.jsaix.cn/chenc/aix-docker.git /data/aix-docker + if [ $? -ne 0 ]; then + print_error "git clone aix-docker failed" + exit 1 + fi +fi +pushd /data/aix-docker + +yaml_file=$(find "$(pwd)" -type f -name "*.yaml" -o -name "*.yml" | head -n 1) +if [ -n "$yaml_file" ]; then + if [ -z "$AIX_DOCKER_COMPOSER_FILE" ]; then + echo 'export AIX_DOCKER_COMPOSER_FILE=$yaml_file' >> ~/.bashrc + source ~/.bashrc + print_success "AIX_DOCKER_COMPOSER_FILE environment variable set to '$yaml_file'" + else + echo "AIX_DOCKER_COMPOSER_FILE is already set to: $AIX_DOCKER_COMPOSER_FILE" + fi +else + print_error "Please config docker composer startup yaml file" + exit 1 +fi +if grep -q "/data/aix-docker/.alias" ~/.bashrc; then + print_success ".alias is already sourced in ~/.bashrc" +else + echo "source /data/aix-docker/.alias" >> ~/.bashrc + source ~/.bashrc +fi +touch /root/.aix_docker.lock +print_success "script init success!" \ No newline at end of file