-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathnginx
executable file
·105 lines (94 loc) · 3.06 KB
/
nginx
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
#!/bin/bash
if [ -z "$COOG_CODE_DIR" ] || [ ! -d "$COOG_CODE_DIR" ] || [ -z "$COOG_DATA_DIR" ]
then
{
echo "Please make sure that these two env vars are set:"
echo " COOG_CODE_DIR: your coog-admin install folder"
echo " COOG_DATA_DIR: the folder where to keep your custom config"
} >&2 && exit 1
fi
_edit_ls() {
echo
( cd "$COOG_DATA_DIR/nginx" && find . -type f | cut -c 3- )
}
_edit_commit() {
config_data_path_changed "nginx*" \
&& git add nginx* \
&& config_data_commit -m "update nginx - $1"
}
_edit() {
[ -z "$1" ] && echo "choose file to edit:" \
&& _edit_ls \
&& return 1
local f; f="$COOG_DATA_DIR/nginx/$1"
[ ! -f "$f" ] \
&& echo "bad file name, choose within:" \
&& _edit_ls \
&& return 1
"$EDITOR" "$COOG_DATA_DIR/nginx/$1"
( cd "$COOG_DATA_DIR" && _edit_commit "$1" )
}
_ssl() {
[ ! -z "$NGINX_SSL_METHOD" ] && source "$COOG_CODE_DIR/ssl/$NGINX_SSL_METHOD/init"
[ ! -z "$NGINX_SSL_METHOD" ] && prepare_ssl
}
_check() {
local n; n=$(cat "$COOG_DATA_DIR/nginx/"*web.conf | wc -l)
[ -z "$WEB_IMAGE" ] \
&& [ "$n" -ne 0 ] \
&& echo "nginx and web configuration are not compliant (nginx y, web: n) - ./nginx reset to solve" \
&& return 1
[ ! -z "$WEB_IMAGE" ] \
&& [ "$n" -eq 0 ] \
&& echo "nginx and web configuration are not compliant (nginx n, web: y) - ./nginx reset to solve" \
&& return 1
return 0
}
run() {
_check || return $?
local volumes
[ ! -z "$COOG_IMAGE" ] \
&& volumes="$volumes --volumes-from $NETWORK_NAME-coog-server"
[ ! -z "$WEB_IMAGE" ] \
&& volumes="$volumes --volumes-from $NETWORK_NAME-web"
[ ! -z "$NGINX_SSL_METHOD" ] \
&& source "$COOG_CODE_DIR/ssl/$NGINX_SSL_METHOD/init" \
&& volumes="$volumes $SSL_VOLUMES"
docker run \
$DOCKER_DAEMON_OPTS \
--network "$NETWORK_NAME" \
--name "$NETWORK_NAME-nginx" \
-v /usr/share/zoneinfo:/usr/share/zoneinfo:ro \
-v /etc/timezone:/etc/timezone:ro \
-v "$NGINX_VOLUME/nginx.conf:/etc/nginx/nginx.conf:ro" \
-v "$NGINX_VOLUME:/etc/nginx/coog/:ro" \
$volumes \
-p "$NGINX_SSL_PUB_PORT:443" \
-p "$NGINX_PUB_PORT:80" \
"$NGINX_IMAGE"
}
action() {
docker "$@" "$NETWORK_NAME-nginx"
}
usage() {
echo
echo Available commands
echo
echo " reset -> reset nginx configuration"
echo " edit -> edit nginx configuration"
echo " ssl -> prepare SSL certificate"
echo " run -> run an nginx docker image"
echo " <action> -> call docker action on server container"
echo
}
main() {
source "$COOG_CODE_DIR/config"
[ -z "$1" ] && usage && return 0
local cmd; cmd="$1"; shift
[ "$cmd" = "reset" ] && { ( cd "$COOG_DATA_DIR" && config_data_reset_nginx ); return $?; }
[ "$cmd" = "edit" ] && { _edit "$@"; return $?; }
[ "$cmd" = "ssl" ] && { _ssl; return $?; }
[ "$cmd" = "run" ] && { run; return $?; }
action "$cmd" "$@"
}
main "$@"