Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tkuchiki
Created July 27, 2017 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkuchiki/e52c1a8649343f24a5c4b501d9f033a2 to your computer and use it in GitHub Desktop.
Save tkuchiki/e52c1a8649343f24a5c4b501d9f033a2 to your computer and use it in GitHub Desktop.
apache(httpd) でファイルの有無で 503 を返すようにする
  • DocumentRoot = /var/www/html なので 503.html は /var/www/html/503.html にあるとする
  • /tmp/503 があればステータスコード 503 + 503.thml を返す

/tmp/503 は cron や at で作成、削除すれば一定期間だけ自動でメンテにできそう。

# メンテ開始
at $(LANG=C date +"%H:%M %Y-%m-%d" -d "2017-07-27T08:00") -f /path/to/start_maintenance.sh

# メンテ終了
at $(LANG=C date +"%H:%M %Y-%m-%d" -d "2017-07-27T09:30") -f /path/to/end_maintenance.sh
#!/bin/sh
rm -f /tmp/503
<VirtualHost *:80>
ServerName localhost
DocumentRoot /var/www/html
<Location />
ErrorDocument 503 /503.html
RewriteEngine On
RewriteCond /tmp/503 -f
RewriteCond %{REQUEST_URI} !=/503.html
RewriteCond %{REMOTE_ADDR} !=127.0.0.1
RewriteRule ^.*$ - [R=503,L]
</Location>
</VirtualHost>
#!/bin/sh
touch /tmp/503
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment