diff --git a/ocs/v1.php b/ocs/v1.php
index d69904fc4954c8f898f1e945e2d3d1d97c297d93..624355a850122fc3fb684b6588748313861da17b 100644
--- a/ocs/v1.php
+++ b/ocs/v1.php
@@ -23,6 +23,14 @@
 
 require_once '../lib/base.php';
 
+if (\OCP\Util::needUpgrade()) {
+	// since the behavior of apps or remotes are unpredictable during
+	// an upgrade, return a 503 directly
+	OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
+	OC_Template::printErrorPage('Service unavailable');
+	exit;
+}
+
 use Symfony\Component\Routing\Exception\ResourceNotFoundException;
 use Symfony\Component\Routing\Exception\MethodNotAllowedException;
 
diff --git a/public.php b/public.php
index eed63948112831bb57349da8117f0086edb71470..1f858fd073d6f684dd7bc62415757d2f74b5f8ff 100644
--- a/public.php
+++ b/public.php
@@ -3,6 +3,14 @@
 try {
 
 	require_once 'lib/base.php';
+	if (\OCP\Util::needUpgrade()) {
+		// since the behavior of apps or remotes are unpredictable during
+		// an upgrade, return a 503 directly
+		OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
+		OC_Template::printErrorPage('Service unavailable');
+		exit;
+	}
+
 	OC::checkMaintenanceMode();
 	OC::checkSingleUserMode();
 	$pathInfo = OC_Request::getPathInfo();