# Put the application in maintenance with PAUSESERVER()

> Pause the server by name so that every request gets a 503 page, resume it, and know that without a second argument the call toggles.

Framework: total5
Product: Total.js 5 (total5@0.0.19)
Language: en
Content-SHA256: 9906e044fb40f45c1560ab417e7d4840431f15fe4159546344939e06b8075510
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: total5-installed@total5@0.0.19
Review: not-recorded

`PAUSESERVER(name, true)` pauses the server and `PAUSESERVER(name, false)` resumes it. While **at least one name** is paused, every request is answered with the status **503** and the built-in maintenance page (a request made with `xhr` gets a 503 error answer instead of the page). The name only identifies who paused it, so that two parts of the application can pause and resume independently: the server answers again when all the names were resumed.

Without the second argument the call **toggles**: `PAUSESERVER(name)` pauses when the name was not paused and resumes when it was, and returns the new state (`true` when paused).

Because a paused server answers 503 to everything, including the route that would resume it, resume from your own code: a timer, a signal, a task that finishes. The example pauses for a short time and resumes by itself.

```js controllers/maintenance.js
exports.install = function() {
	ROUTE('GET /maintenance/', maintenance);
	ROUTE('GET /toggle/', toggle);
	ROUTE('GET /ping/', ping);
};

function maintenance($) {
	const state = PAUSESERVER('maintenance', true);
	setTimeout(() => PAUSESERVER('maintenance', false), 600);
	$.json({ paused: state });
}

function toggle($) {
	const first = PAUSESERVER('toggled');
	const second = PAUSESERVER('toggled');
	$.json({ first: first, second: second });
}

function ping($) {
	$.json({ ok: true });
}
```
