diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..7e047d3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 Loïc Guitaut + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..fb1aa14 --- /dev/null +++ b/README.md @@ -0,0 +1,66 @@ +# dokku-maintenance + +dokku-maintenance is a plugin for [dokku][dokku] that gives the ability to enable or disable maintenance mode for an application. + +## Installation + +```sh +$ sudo git clone https://github.com/Flink/dokku-maintenance.git /var/lib/dokku/plugins/maintenance +``` + +## Commands + +``` +$ dokku help + maintenance Display the current maintenance status of app + maintenance:custom-page Imports a tarball from stdin; should contain at least maintenance.html + maintenance:off Take the app out of maintenance mode + maintenance:on Put the app into maintenance mode +``` + +## Usage + +Check maintenance status of my-app +``` +# dokku maintenance my-app # Server side +$ ssh dokku@server maintenance my-app # Client side + +-----> Maintenance status of my-app: + off +``` + +Enable maintenance mode for my-app +``` +# dokku maintenance:on my-app # Server side +$ ssh dokku@server maintenance:on my-app # Client side + +-----> Enabling maintenance mode for ruby-test... + done +``` + +Disable maintenance mode for my-app +``` +# dokku maintenance:off my-app # Server side +$ ssh dokku@server maintenance:off my-app # Client side + +-----> Disabling maintenance mode for ruby-test... + done +``` + +Use a custom page for maintenance +``` +# dokku maintenance:custom-page my-app < my-custom-page.tar # Server side +$ ssh dokku@server maintenance:custom-page my-app < my-custom-page.tar # Client side + +-----> Importing custom maintenance page... +maintenance.html +image.jpg + done +``` +You have to provide at least a maintenance.html page but you can provide images, css, custom font, etc. if you want. Just write absolute paths in your html and not relative ones (so to serve image.jpg which is at the same level than your maintenance.html page you’ll write “/image.jpg” instead of “./image.jpg” or “image.jpg”). + +## License + +This plugin is released under the MIT license. See the file [LICENSE](LICENSE). + +[dokku]: https://github.com/progrium/dokku diff --git a/commands b/commands new file mode 100755 index 0000000..bbd1eb4 --- /dev/null +++ b/commands @@ -0,0 +1,89 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$(dirname $0)/../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) + cat && cat< Display the current maintenance status of app + maintenance:on Put the app into maintenance mode + maintenance:off Take the app out of maintenance mode + maintenance:custom-page Imports a tarball from stdin; should contain at least maintenance.html +EOF + ;; + + *) + exit $DOKKU_NOT_IMPLEMENTED_EXIT + ;; + +esac diff --git a/templates/maintenance.conf b/templates/maintenance.conf new file mode 100644 index 0000000..575e117 --- /dev/null +++ b/templates/maintenance.conf @@ -0,0 +1,11 @@ +location ~* ^(.*)$ { + root {APP_ROOT}/maintenance/; + try_files $uri =503; +} + +error_page 503 @maintenance; + +location @maintenance { + root {APP_ROOT}/maintenance/; + rewrite ^(.*)$ /maintenance.html break; +} diff --git a/templates/maintenance.html b/templates/maintenance.html new file mode 100644 index 0000000..2185e7d --- /dev/null +++ b/templates/maintenance.html @@ -0,0 +1,42 @@ + + + + + Application Offline for Maintenance + + + +
+

Application Offline for Maintenance

+
+

This application is undergoing maintenance right now. Please check back later.

+
+
+ +