Skip to content

Commit

Permalink
First release of dokku-maintenance plugin
Browse files Browse the repository at this point in the history
With this plugin you can:
- Put your app into maintenance
- Take your app out of maintenance
- Check if your app maintenance status
- Use a custom maintenance page
  • Loading branch information
Flink committed Mar 6, 2015
0 parents commit b3f62ac
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 0 deletions.
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.

66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 <app> Display the current maintenance status of app
maintenance:custom-page <app> Imports a tarball from stdin; should contain at least maintenance.html
maintenance:off <app> Take the app out of maintenance mode
maintenance:on <app> 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
89 changes: 89 additions & 0 deletions commands
Original file line number Diff line number Diff line change
@@ -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<<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
;;

*)
exit $DOKKU_NOT_IMPLEMENTED_EXIT
;;

esac
11 changes: 11 additions & 0 deletions templates/maintenance.conf
Original file line number Diff line number Diff line change
@@ -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;
}
42 changes: 42 additions & 0 deletions templates/maintenance.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Application Offline for Maintenance</title>
<style type="text/css">
body {
background-color: white;
color: #333333;
font-family: Arial, sans-serif;
margin: 0;
padding: 36px;
line-height: 18px;
font-size: 14px;
}
.section {
margin-bottom: 36px;
color: #222222;
}
.section h1 {
font-size: 26px;
background-color: #dad8e4;
padding: 18px 22px 15px 22px;
margin: 0;
overflow: hidden;
}
.article {
border: 4px solid #dad8e4;
padding: 24px 18px 18px 18px;
font-size: 14px;
}
</style>
</head>
<body>
<div class="section">
<h1>Application Offline for Maintenance</h1>
<div class="article">
<p>This application is undergoing maintenance right now. Please check back later.</p>
</div>
</div>
</body>
</html>

0 comments on commit b3f62ac

Please sign in to comment.