diff --git a/Zotlabs/Daemon/Run.php b/Zotlabs/Daemon/Run.php index a7987e47e..a8ca219bd 100644 --- a/Zotlabs/Daemon/Run.php +++ b/Zotlabs/Daemon/Run.php @@ -19,6 +19,9 @@ if (array_search( __file__ , get_included_files()) === 0) { class Run { static public function Summon($arr) { + if (file_exists('maintenance_lock') || file_exists('cache/maintenance_lock')) { + return; + } proc_run('php','Zotlabs/Daemon/Run.php',$arr); } diff --git a/Zotlabs/Web/WebServer.php b/Zotlabs/Web/WebServer.php index c3a7fc391..a059d99d7 100644 --- a/Zotlabs/Web/WebServer.php +++ b/Zotlabs/Web/WebServer.php @@ -15,6 +15,10 @@ class WebServer { require_once('boot.php'); + if (file_exists('maintenance_lock') || file_exists('cache/maintenance_lock')) { + http_status_exit(503,'System unavailable'); + } + sys_boot(); diff --git a/util/maintenance b/util/maintenance new file mode 100755 index 000000000..fbc06a574 --- /dev/null +++ b/util/maintenance @@ -0,0 +1,40 @@ +#!/bin/bash + +# enable, disable or check the maintenance mode. +# If enabled, web access and execution of background tasks are blocked. +# Interaction with the server is only possible through foreground scripts +# We look for the existence of two files: maintenance_lock and cache/maintenance_lock +# and if either exist the system is locked. We attempt to create and remove both of these. +# One or the other _may_ fail due to permissions or ownership issues but the other will +# usually succeed. + +if [ $# -ne 0 ]; then + action=$1 +else + if [ -f maintenance_lock -o -f cache/maintenance_lock ]; then + echo "Maintenance mode is enabled" + else + echo "Maintenance mode is disabled" + fi + echo Usage: $0 'on|off' + exit +fi + +if [ $1 == 'on' ]; then + touch maintenance_lock > /dev/null 2>&1 + touch cache/maintenance_lock > /dev/null 2>&1 + if [ -f maintenance_lock -o -f cache/maintenance_lock ]; then + echo "Maintenance mode is enabled" + else + echo "Failed: Maintenance mode is disabled" + fi +fi +if [ $1 == 'off' ]; then + rm maintenance_lock > /dev/null 2>&1 + rm cache/maintenance_lock > /dev/null 2>&1 + if [ -f maintenance_lock -o -f cache/maintenance_lock ]; then + echo "Failed: Maintenance mode is enabled" + else + echo "Maintenance mode is disabled" + fi +fi