forked from dokku/dokku-maintenance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands
executable file
·100 lines (90 loc) · 2.98 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
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
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
PLUGIN_BASE_PATH="$PLUGIN_PATH"
if [[ -n $DOKKU_API_VERSION ]]; then
PLUGIN_BASE_PATH="$PLUGIN_ENABLED_PATH"
fi
source "$PLUGIN_BASE_PATH/common/functions"
reload_nginx () {
case "$DOKKU_DISTRO" in
ubuntu)
sudo /etc/init.d/nginx reload > /dev/null
;;
opensuse)
sudo /sbin/service nginx reload > /dev/null
;;
esac
}
case "$1" in
maintenance:on)
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
verify_app_name "$2"
APP="$2"
dokku_log_info1 "Enabling maintenance mode for $APP..."
if [[ ! -d "$DOKKU_ROOT/$APP/nginx.conf.d" ]]; then
mkdir "$DOKKU_ROOT/$APP/nginx.conf.d"
fi
if [[ ! -d "$DOKKU_ROOT/$APP/maintenance" ]]; then
mkdir "$DOKKU_ROOT/$APP/maintenance"
cp "$(dirname $0)/templates/maintenance.html" "$DOKKU_ROOT/$APP/maintenance"
fi
cp "$(dirname $0)/templates/maintenance.conf" "$DOKKU_ROOT/$APP/nginx.conf.d"
sed -i "s,{APP_ROOT},$DOKKU_ROOT/$APP," "$DOKKU_ROOT/$APP/nginx.conf.d/maintenance.conf"
reload_nginx
dokku_log_verbose "done"
;;
maintenance:off)
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
verify_app_name "$2"
APP="$2"
dokku_log_info1 "Disabling maintenance mode for $APP..."
if [[ -f "$DOKKU_ROOT/$APP/nginx.conf.d/maintenance.conf" ]]; then
rm "$DOKKU_ROOT/$APP/nginx.conf.d/maintenance.conf"
fi
reload_nginx
dokku_log_verbose "done"
;;
maintenance)
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
verify_app_name "$2"
APP="$2"
dokku_log_info1 "Maintenance status of $APP: "
MAINTENANCE_STATUS="off"
if [[ -f "$DOKKU_ROOT/$APP/nginx.conf.d/maintenance.conf" ]]; then
MAINTENANCE_STATUS="on"
fi
dokku_log_verbose "$MAINTENANCE_STATUS"
;;
maintenance:custom-page)
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
verify_app_name "$2"
[[ -t 0 ]] && echo "Tar archive containing at least maintenance.html expected on stdin" && exit 1
APP="$2"
dokku_log_info1 "Importing custom maintenance page..."
TEMP_DIR=$(mktemp -d)
cd $TEMP_DIR
tar xvf - <&0
[[ ! -f "$TEMP_DIR/maintenance.html" ]] && echo "Tar archive missing maintenance.html" && exit 1
mkdir -p "$DOKKU_ROOT/$APP/maintenance"
mv $TEMP_DIR/* "$DOKKU_ROOT/$APP/maintenance"
rm -rf $TEMP_DIR
dokku_log_verbose "done"
;;
help | maintenance:help)
HELP=$(cat<<EOF
maintenance <app>, Display the current maintenance status of app
maintenance:on <app>, Put the app into maintenance mode
maintenance:off <app>, Take the app out of maintenance mode
maintenance:custom-page <app>, Imports a tarball from stdin; should contain at least maintenance.html
EOF
)
if [[ -n $DOKKU_API_VERSION ]]; then
echo "$HELP"
else
cat && echo "$HELP"
fi
;;
*)
exit $DOKKU_NOT_IMPLEMENTED_EXIT
;;
esac