-
Notifications
You must be signed in to change notification settings - Fork 21
/
commands
executable file
·75 lines (64 loc) · 1.73 KB
/
commands
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
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
# Check if name is specified
if [[ $1 == domains ]] || [[ $1 == domains:* ]]; then
if [[ -z $2 ]]; then
echo "You must specify an app name"
exit 1
else
APP="$2"
DOMAINS_FILE="$DOKKU_ROOT/$APP/DOMAINS"
# Check if app exists with the same name
if [ ! -d "$DOKKU_ROOT/$APP" ]; then
echo "App $APP does not exist"
exit 1
fi
[ -f $DOMAINS_FILE ] || {
echo "-----> Creating $DOMAINS_FILE"
touch $DOMAINS_FILE
}
fi
fi
case "$1" in
domains)
cat $DOMAINS_FILE
;;
domains:set)
if [[ -z "${*:3}" ]]; then
echo "Usage: dokku domains:set APP DOMAIN1 [DOMAIN2 ...]"
echo "Must specify a DOMAIN."
exit 1
fi
domains="${*:3}"
PORT=$(< "$DOKKU_ROOT/$APP/PORT")
echo "$domains" > $DOMAINS_FILE
# default nginx.conf
cat<<EOF > $DOKKU_ROOT/$APP/nginx-domains.conf
upstream $APP-domains { server 127.0.0.1:$PORT; }
server {
listen [::]:80;
listen 80;
server_name $domains;
location / {
proxy_pass http://$APP-domains;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host \$http_host;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_set_header X-Forwarded-For \$remote_addr;
proxy_set_header X-Forwarded-Port \$server_port;
proxy_set_header X-Request-Start \$msec;
}
}
EOF
pluginhook nginx-pre-reload $APP
sudo /etc/init.d/nginx reload
;;
help)
cat && cat<<EOF
domains <app> display the domains for an app
domains:set <app> DOMAIN1 [DOMAIN2 ...] set one or more domains
EOF
;;
esac