Permalink
Browse files

Add support for running in maintenance mode

In maintenance mode, a static page is served for all URLs and workers do nothing.
  • Loading branch information...
bladealslayer committed Nov 30, 2016
1 parent d47e46f commit 264387768ae757ed315033d47c86c616d4b4bf41
View
@@ -41,6 +41,9 @@ RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-
# Sharetribe
#
# Install nginx - used to serve maintenance mode page
RUN apt-get install -y nginx
# Install latest bundler
RUN gem install bundler
@@ -0,0 +1,70 @@
# Static webserver configuration for maintenance mode
# Set MAINTENANCE_MODE environment variable to "true"
# to enable maintenance mode. See also script/startup.sh.
master_process on;
daemon off;
error_log /dev/stdout;
pid tmp/nginx.pid;
worker_processes 1;
events {
worker_connections 4096;
}
http {
##
# Basic Settings
##
client_body_temp_path tmp/client_body;
fastcgi_temp_path tmp/fastcgi_temp;
proxy_temp_path tmp/proxy_temp;
scgi_temp_path tmp/scgi_temp;
uwsgi_temp_path tmp/uwsgi_temp;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server_tokens off;
server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log off;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
server {
server_name _;
listen 0.0.0.0:3000;
root 'public/maintenance_page';
access_log /dev/stdout;
error_page 503 /maintenance.html;
location / {
if (!-f $request_filename) {
return 503;
}
}
location /_health {
default_type text/plain;
}
}
}
View
@@ -31,4 +31,4 @@ services:
# scheduled task definitions
# Uncomment when deploying own installation of Sharetribe
#- convox.cron.test-task=0 9 * * ? bundle exec rails runner CommunityMailer.deliver_community_updates
command: [ "bundle", "exec", "rake", "jobs:work" ]
command: [ "script/startup.sh", "worker" ]
@@ -0,0 +1 @@
OK
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Internal Server Error (500)</title>
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:400,600' rel='stylesheet' type='text/css'>
<style type="text/css">
html, body {
background-color: #f6f7f7;
font-family: 'Source Sans Pro', sans-serif;
text-align: center;
color: #333;
}
h2 {
padding: 60px 20px 10px;
font-size: 26px;
}
p {
padding: 0 50px;
font-size: 18px;
line-height: 28px;
padding-bottom: 60px;
}
.box {
max-width: 620px;
width: 90%;
background-color: #ffffff;
border-radius: 5px;
margin: 10% auto 0;
}
</style>
</head>
<body>
<div class="box">
<h2>The marketplace is temporarily down for maintenance</h2>
<p>Please try again in few moments.</p>
</div>
</body>
</html>
View
@@ -1,5 +1,34 @@
#!/bin/bash
rm -f tmp/pids/server.pid
set -e
exec bundle exec passenger start -p "${PORT-3000}" --min-instances "${PASSENGER_MIN_INSTANCES-1}" --max-pool-size "${PASSENGER_MAX_POOL_SIZE-1}"
# Expect to be passed either 'web' or 'worker' as parameter
APP_MODE="${1-web}"
case "$APP_MODE" in
web)
if [[ "$MAINTENANCE_MODE" == "true" ]] ; then
exec /usr/sbin/nginx -p /opt/app -c config/nginx_maintenance.conf
else
rm -f tmp/pids/server.pid
exec bundle exec passenger \
start \
-p "${PORT-3000}" \
--min-instances "${PASSENGER_MIN_INSTANCES-1}" \
--max-pool-size "${PASSENGER_MAX_POOL_SIZE-1}"
fi
;;
worker)
if [[ "$MAINTENANCE_MODE" == "true" ]] ; then
# Do nothing
exec sleep 86400
else
exec bundle exec rake jobs:work
fi
;;
*)
echo "Unknown process type. Must be either 'web' or 'worker'!"
exit 1
;;
esac

0 comments on commit 2643877

Please sign in to comment.