-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver
executable file
·131 lines (116 loc) · 3.82 KB
/
server
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
set -euo pipefail
directory="$(dirname -- "$(readlink -f -- "$0" || greadlink -f -- "$0")")"
source "$directory/docker/utilities/common"
# Display usage information
usage() {
cat <<EOF
${CYAN}Usage:${NC}
$0 {up|start|reload|stop|down|reboot|restart|rebuild|cli|core|tools|lzd|help}
or
server {up|start|reload|stop|down|reboot|restart|rebuild|cli|core|tools|lzd|help}
Commands:
${YELLOW}up${NC} Start Docker services (foreground)
${YELLOW}start, reload${NC} Start or reload Docker services (background)
${YELLOW}stop, down${NC} Stop or shut down Docker services
${YELLOW}reboot, restart${NC} Restart Docker services
${YELLOW}rebuild${NC} Rebuild Docker images with no cache
${YELLOW}cli${NC} Access the PHP container based on a domain configuration
${YELLOW}core${NC} Access the Core container as 'devuser'
${YELLOW}tools${NC} Access the SERVER_TOOLS container as 'devuser'
${YELLOW}lzd${NC} Launch LazyDocker in the SERVER_TOOLS container
${YELLOW}help${NC} Show this usage guide
EOF
}
if [ $# -eq 0 ]; then
echo -e "${RED}Error: No command provided.${NC}"
usage
exit 1
fi
source "$directory/docker/utilities/main"
check_required_commands "docker" "readlink"
check_file_existence "/.env"
ensure_files_exist \
"/docker/.env" \
"/configuration/php/php.ini" \
"/configuration/scheduler/supervisor-worker.conf" \
"/configuration/scheduler/supervisor-logrotate"
update_env "$directory/docker/.env" "WORKING_DIR" "$directory"
copy_files "/configuration/scheduler/" "/docker/conf/docker-files/cli/" "*" ".gitignore"
# Handle provided commands
case "$1" in
up)
docker_compose up
;;
start | reload)
docker_compose up -d
reload_http_containers
;;
stop | down)
docker_compose down
;;
reboot | restart)
docker_compose down && docker_compose up -d
reload_http_containers
;;
rebuild)
docker_compose down && docker_compose build --no-cache --pull "${@:2}"
;;
config)
docker_compose config
;;
http)
if [ "$2" = reload ]; then
reload_http_containers
fi
;;
core)
if [ -z "$2" ]; then
echo -e "${RED}Please provide a domain (e.g., ./server core test.com).${NC}"
exit 1
fi
domain="$2"
conf_file=""
# Define Apache and Nginx configuration file paths
apache_conf="$directory/configuration/apache/$domain.conf"
nginx_conf="$directory/configuration/nginx/$domain.conf"
# Check for the config file in Apache or Nginx directories
if [ -f "$apache_conf" ]; then
conf_file="$apache_conf"
elif [ -f "$nginx_conf" ]; then
conf_file="$nginx_conf"
else
echo -e "${RED}No configuration file found for $domain.${NC}"
exit 1
fi
# Extract PHP container and doc root from config file
php_container=$(grep -oP '(?<=fcgi://)[^:]+(?=:9000)' "$conf_file")
doc_root=$(grep -oP '(?<=/app)[^"]+' "$conf_file")
# Validate PHP container and document root
if [ -z "$php_container" ] || [ -z "$doc_root" ]; then
echo -e "${RED}Could not determine PHP container or document root for $domain.${NC}"
exit 1
fi
# Adjust PHP container naming (e.g., php83 -> PHP_8.3)
php_version="${php_container//php/}"
php_container="PHP_${php_version:0:1}.${php_version:1}"
echo -e "${GREEN}Launching into $php_container's bash panel and cd'ing to /app$doc_root...${NC}"
# Execute into PHP container and change directory
docker exec -it "$php_container" bash -c "cd /app$doc_root && sudo -u devuser /bin/bash"
;;
tools)
docker exec -it SERVER_TOOLS bash -c "sudo -u devuser /bin/bash"
;;
lzd)
docker exec -it SERVER_TOOLS lazydocker
;;
help)
usage
;;
*)
echo -e "${RED}Invalid command: $1${NC}"
usage
exit 1
;;
esac
unset directory