# maintenance

(plugins.maintenance)

## Overview

The `MaintenanceProvider` class supports server maintenance and database management within a plugin framework, enabling controlled interactions with servers and connected clients. Its primary purpose is to facilitate operations during specific contexts, such as solution import hooks, ensuring a streamlined approach to system maintenance.

This class allows managing the server's maintenance mode, enabling or disabling it dynamically while also verifying the current status. Through integration with a maintenance service, it ensures that these operations are only performed in valid scenarios, such as before or after solution imports. Additionally, it provides the capability to interact with connected clients by retrieving client information, sending messages, and even disconnecting specific or all clients from the server.

Database management features include accessing information about servers and their associated tables, retrieving server names under specific conditions like being active or valid, and identifying clones of database models. Robust exception handling and logging ensure operational reliability and debugging of remote interactions.

## **Returned Types**

[JSMaintenanceClientInformation](/reference/servoyextensions/server-plugins/maintenance/jsmaintenanceclientinformation.md),[JSServer](/reference/servoyextensions/server-plugins/maintenance/jsserver.md),[JSTableObject](/reference/servoyextensions/server-plugins/maintenance/jstableobject.md),[JSColumnObject](/reference/servoyextensions/server-plugins/maintenance/jscolumnobject.md),

## Methods Summarized

| Type                                                                           | Name                                                                                                                                    | Summary                                                                                                                                                                                                                                                           |
| ------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [JSServer](/reference/servoyextensions/server-plugins/maintenance/jsserver.md) | [getServer(serverName)](#getserver-servername)                                                                                          | Retrieves an instance of JSServer corresponding to the server with the name specified through the "serverName" argument.                                                                                                                                          |
| [JSServer](/reference/servoyextensions/server-plugins/maintenance/jsserver.md) | [getServer(serverName, mustBeEnabled)](#getserver-servername-mustbeenabled)                                                             | Retrieves an instance of JSServer corresponding to the server with the name specified through the "serverName" argument.                                                                                                                                          |
| [JSServer](/reference/servoyextensions/server-plugins/maintenance/jsserver.md) | [getServer(serverName, mustBeEnabled, mustBeValid)](#getserver-servername-mustbeenabled-mustbevalid)                                    | Retrieves an instance of JSServer corresponding to the server with the name specified through the "serverName" argument.                                                                                                                                          |
| [Array](/reference/servoycore/dev-api/js-lib/array.md)                         | [getServerNames()](#getservernames)                                                                                                     | Retrieves a list with the names of all available database servers.                                                                                                                                                                                                |
| [Array](/reference/servoycore/dev-api/js-lib/array.md)                         | [getServerNames(mustBeEnabled)](#getservernames-mustbeenabled)                                                                          | Retrieves a list with the names of all available database servers.                                                                                                                                                                                                |
| [Array](/reference/servoycore/dev-api/js-lib/array.md)                         | [getServerNames(mustBeEnabled, mustBeValid)](#getservernames-mustbeenabled-mustbevalid)                                                 | Retrieves a list with the names of all available database servers.                                                                                                                                                                                                |
| [Array](/reference/servoycore/dev-api/js-lib/array.md)                         | [getServerNames(mustBeEnabled, mustBeValid, sort)](#getservernames-mustbeenabled-mustbevalid-sort)                                      | Retrieves a list with the names of all available database servers.                                                                                                                                                                                                |
| [Array](/reference/servoycore/dev-api/js-lib/array.md)                         | [getServerNames(mustBeEnabled, mustBeValid, sort, includeDuplicates)](#getservernames-mustbeenabled-mustbevalid-sort-includeduplicates) | Retrieves a list with the names of all available database servers.                                                                                                                                                                                                |
| [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md)                     | [isInMaintenanceMode()](#isinmaintenancemode)                                                                                           | Returns true if the server is in maintenance mode, false otherwise.                                                                                                                                                                                               |
| void                                                                           | [setMaintenanceMode(maintenanceMode)](#setmaintenancemode-maintenancemode)                                                              | Puts the server into/out of maintenance mode, depending on the boolean parameter that is specified (if the parameter is true, then the server will be put into maintenance mode; if the parameter is false, then the server will be put out of maintenance mode). |

## Methods Detailed

### getServer(serverName)

Retrieves an instance of JSServer corresponding to the server with the name specified through the "serverName" argument.\
If the optional argument "mustBeEnabled" is set to true, then the JSServer instance is returned only if the server is active.\
Similarly, if the "mustBeValid" optional argument is set to true, then the JSServer instance is returned only if the server is valid.\
If the specified server is not found, or if it does not meet the requirements imposed by the optional arguments, then null is returned.\
By default both optional arguments have the value false.

**Parameters**

* [String](/reference/servoycore/dev-api/js-lib/string.md) **serverName** ;

**Returns:** [JSServer](/reference/servoyextensions/server-plugins/maintenance/jsserver.md) the JSServer instance corresponding to the specified server name, or null if the server does not exist or does not meet the conditions.

**Sample**

```js
// WARNING: maintenance plugin is only meant to run during solution import using before or after import hook(so not from client)
//Retrieves an instance of JSServer corresponding to the server with the name specified through the "serverName" argument.
//If the optional argument "mustBeEnabled" is set to true, then the JSServer instance is returned only if the server is active.
//Similarly, if the "mustBeValid" optional argument is set to true, then the JSServer instance is returned only if the server is valid.
//If the specified server is not found, or if it does not meet the requirements imposed by the optional arguments, then null is returned.
//By default both optional arguments have the value false.
var server = plugins.maintenance.getServer("example_data");
if (server) {
	var tableNames = server.getTableNames();
	application.output("There are " + tableNames.length + " tables.");
	for (var i=0; i<tableNames.length; i++)
		application.output("Table " + i + ": " + tableNames[i]);
}
else {
	plugins.dialogs.showInfoDialog("Attention","Server 'example_data' cannot be found.","OK");
}
```

### getServer(serverName, mustBeEnabled)

Retrieves an instance of JSServer corresponding to the server with the name specified through the "serverName" argument.\
If the optional argument "mustBeEnabled" is set to true, then the JSServer instance is returned only if the server is active.\
Similarly, if the "mustBeValid" optional argument is set to true, then the JSServer instance is returned only if the server is valid.\
If the specified server is not found, or if it does not meet the requirements imposed by the optional arguments, then null is returned.\
By default both optional arguments have the value false.

**Parameters**

* [String](/reference/servoycore/dev-api/js-lib/string.md) **serverName** ;
* [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) **mustBeEnabled** ;

**Returns:** [JSServer](/reference/servoyextensions/server-plugins/maintenance/jsserver.md) the JSServer instance corresponding to the specified server name if it is enabled (when mustBeEnabled is true), or null otherwise.

**Sample**

```js
// WARNING: maintenance plugin is only meant to run during solution import using before or after import hook(so not from client)
//Retrieves an instance of JSServer corresponding to the server with the name specified through the "serverName" argument.
//If the optional argument "mustBeEnabled" is set to true, then the JSServer instance is returned only if the server is active.
//Similarly, if the "mustBeValid" optional argument is set to true, then the JSServer instance is returned only if the server is valid.
//If the specified server is not found, or if it does not meet the requirements imposed by the optional arguments, then null is returned.
//By default both optional arguments have the value false.
var server = plugins.maintenance.getServer("example_data");
if (server) {
	var tableNames = server.getTableNames();
	application.output("There are " + tableNames.length + " tables.");
	for (var i=0; i<tableNames.length; i++)
		application.output("Table " + i + ": " + tableNames[i]);
}
else {
	plugins.dialogs.showInfoDialog("Attention","Server 'example_data' cannot be found.","OK");
}
```

### getServer(serverName, mustBeEnabled, mustBeValid)

Retrieves an instance of JSServer corresponding to the server with the name specified through the "serverName" argument.\
If the optional argument "mustBeEnabled" is set to true, then the JSServer instance is returned only if the server is active.\
Similarly, if the "mustBeValid" optional argument is set to true, then the JSServer instance is returned only if the server is valid.\
If the specified server is not found, or if it does not meet the requirements imposed by the optional arguments, then null is returned.\
By default both optional arguments have the value false.

**Parameters**

* [String](/reference/servoycore/dev-api/js-lib/string.md) **serverName** ;
* [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) **mustBeEnabled** ;
* [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) **mustBeValid** ;

**Returns:** [JSServer](/reference/servoyextensions/server-plugins/maintenance/jsserver.md) the JSServer instance corresponding to the specified server name if it is enabled and valid (when mustBeEnabled and mustBeValid are true), or null otherwise.

**Sample**

```js
// WARNING: maintenance plugin is only meant to run during solution import using before or after import hook(so not from client)
//Retrieves an instance of JSServer corresponding to the server with the name specified through the "serverName" argument.
//If the optional argument "mustBeEnabled" is set to true, then the JSServer instance is returned only if the server is active.
//Similarly, if the "mustBeValid" optional argument is set to true, then the JSServer instance is returned only if the server is valid.
//If the specified server is not found, or if it does not meet the requirements imposed by the optional arguments, then null is returned.
//By default both optional arguments have the value false.
var server = plugins.maintenance.getServer("example_data");
if (server) {
	var tableNames = server.getTableNames();
	application.output("There are " + tableNames.length + " tables.");
	for (var i=0; i<tableNames.length; i++)
		application.output("Table " + i + ": " + tableNames[i]);
}
else {
	plugins.dialogs.showInfoDialog("Attention","Server 'example_data' cannot be found.","OK");
}
```

### getServerNames()

Retrieves a list with the names of all available database servers. The returned list will contain only enabled servers if the "mustBeEnabled" optional argument is set to true. The list will contain only valid servers if the "mustBeValid" argument is set to true. If the "sort" optional argument is set to true, then the list will be sorted alphabetically. If the "includeDuplicates" optional argument is set to false, then duplicate servers will appear only once in the list. By default, the "mustBeEnabled" and the "mustBeValid" arguments have the value false, while the "sort" and "includeDuplicates" arguments have the value true.

**Returns:** [Array](/reference/servoycore/dev-api/js-lib/array.md) An array of database server names.

**Sample**

```js
// WARNING: maintenance plugin is only meant to run during solution import using before or after import hook(so not from client)
//Retrieves a list with the names of all available database servers. The returned list will contain only enabled servers if the "mustBeEnabled"
//optional argument is set to true. The list will contain only valid servers if the "mustBeValid" argument is set to true. If the "sort" optional
//argument is set to true, then the list will be sorted alphabetically. If the "includeDuplicates" optional argument is set to false, then duplicate
//servers will appear only once in the list. By default, the "mustBeEnabled" and the "mustBeValid" arguments have the value false, while the "sort"
//and "includeDuplicates" arguments have the value true.
var serverNames = plugins.maintenance.getServerNames();
application.output("There are " + serverNames.length + " servers.");
for (var i=0; i<serverNames.length; i++)
	application.output("Server " + i + ": " + serverNames[i]);
```

### getServerNames(mustBeEnabled)

Retrieves a list with the names of all available database servers. The returned list will contain only enabled servers if the "mustBeEnabled" optional argument is set to true. The list will contain only valid servers if the "mustBeValid" argument is set to true. If the "sort" optional argument is set to true, then the list will be sorted alphabetically. If the "includeDuplicates" optional argument is set to false, then duplicate servers will appear only once in the list. By default, the "mustBeEnabled" and the "mustBeValid" arguments have the value false, while the "sort" and "includeDuplicates" arguments have the value true.

**Parameters**

* [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) **mustBeEnabled** ;

**Returns:** [Array](/reference/servoycore/dev-api/js-lib/array.md) an array of enabled database server names.

**Sample**

```js
// WARNING: maintenance plugin is only meant to run during solution import using before or after import hook(so not from client)
//Retrieves a list with the names of all available database servers. The returned list will contain only enabled servers if the "mustBeEnabled"
//optional argument is set to true. The list will contain only valid servers if the "mustBeValid" argument is set to true. If the "sort" optional
//argument is set to true, then the list will be sorted alphabetically. If the "includeDuplicates" optional argument is set to false, then duplicate
//servers will appear only once in the list. By default, the "mustBeEnabled" and the "mustBeValid" arguments have the value false, while the "sort"
//and "includeDuplicates" arguments have the value true.
var serverNames = plugins.maintenance.getServerNames();
application.output("There are " + serverNames.length + " servers.");
for (var i=0; i<serverNames.length; i++)
	application.output("Server " + i + ": " + serverNames[i]);
```

### getServerNames(mustBeEnabled, mustBeValid)

Retrieves a list with the names of all available database servers. The returned list will contain only enabled servers if the "mustBeEnabled" optional argument is set to true. The list will contain only valid servers if the "mustBeValid" argument is set to true. If the "sort" optional argument is set to true, then the list will be sorted alphabetically. If the "includeDuplicates" optional argument is set to false, then duplicate servers will appear only once in the list. By default, the "mustBeEnabled" and the "mustBeValid" arguments have the value false, while the "sort" and "includeDuplicates" arguments have the value true.

**Parameters**

* [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) **mustBeEnabled** ;
* [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) **mustBeValid** ;

**Returns:** [Array](/reference/servoycore/dev-api/js-lib/array.md) an array of enabled and valid database server names.

**Sample**

```js
// WARNING: maintenance plugin is only meant to run during solution import using before or after import hook(so not from client)
//Retrieves a list with the names of all available database servers. The returned list will contain only enabled servers if the "mustBeEnabled"
//optional argument is set to true. The list will contain only valid servers if the "mustBeValid" argument is set to true. If the "sort" optional
//argument is set to true, then the list will be sorted alphabetically. If the "includeDuplicates" optional argument is set to false, then duplicate
//servers will appear only once in the list. By default, the "mustBeEnabled" and the "mustBeValid" arguments have the value false, while the "sort"
//and "includeDuplicates" arguments have the value true.
var serverNames = plugins.maintenance.getServerNames();
application.output("There are " + serverNames.length + " servers.");
for (var i=0; i<serverNames.length; i++)
	application.output("Server " + i + ": " + serverNames[i]);
```

### getServerNames(mustBeEnabled, mustBeValid, sort)

Retrieves a list with the names of all available database servers. The returned list will contain only enabled servers if the "mustBeEnabled" optional argument is set to true. The list will contain only valid servers if the "mustBeValid" argument is set to true. If the "sort" optional argument is set to true, then the list will be sorted alphabetically. If the "includeDuplicates" optional argument is set to false, then duplicate servers will appear only once in the list. By default, the "mustBeEnabled" and the "mustBeValid" arguments have the value false, while the "sort" and "includeDuplicates" arguments have the value true.

**Parameters**

* [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) **mustBeEnabled** ;
* [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) **mustBeValid** ;
* [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) **sort** ;

**Returns:** [Array](/reference/servoycore/dev-api/js-lib/array.md) an array of database server names. The array's content may vary depending on the parameters for filtering and sorting.

**Sample**

```js
// WARNING: maintenance plugin is only meant to run during solution import using before or after import hook(so not from client)
//Retrieves a list with the names of all available database servers. The returned list will contain only enabled servers if the "mustBeEnabled"
//optional argument is set to true. The list will contain only valid servers if the "mustBeValid" argument is set to true. If the "sort" optional
//argument is set to true, then the list will be sorted alphabetically. If the "includeDuplicates" optional argument is set to false, then duplicate
//servers will appear only once in the list. By default, the "mustBeEnabled" and the "mustBeValid" arguments have the value false, while the "sort"
//and "includeDuplicates" arguments have the value true.
var serverNames = plugins.maintenance.getServerNames();
application.output("There are " + serverNames.length + " servers.");
for (var i=0; i<serverNames.length; i++)
	application.output("Server " + i + ": " + serverNames[i]);
```

### getServerNames(mustBeEnabled, mustBeValid, sort, includeDuplicates)

Retrieves a list with the names of all available database servers. The returned list will contain only enabled servers if the "mustBeEnabled" optional argument is set to true. The list will contain only valid servers if the "mustBeValid" argument is set to true. If the "sort" optional argument is set to true, then the list will be sorted alphabetically. If the "includeDuplicates" optional argument is set to false, then duplicate servers will appear only once in the list. By default, the "mustBeEnabled" and the "mustBeValid" arguments have the value false, while the "sort" and "includeDuplicates" arguments have the value true.

**Parameters**

* [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) **mustBeEnabled** ;
* [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) **mustBeValid** ;
* [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) **sort** ;
* [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) **includeDuplicates** ;

**Returns:** [Array](/reference/servoycore/dev-api/js-lib/array.md) an array of database server names. The array's content may vary depending on the parameters for filtering, sorting, and duplication.

**Sample**

```js
// WARNING: maintenance plugin is only meant to run during solution import using before or after import hook(so not from client)
//Retrieves a list with the names of all available database servers. The returned list will contain only enabled servers if the "mustBeEnabled"
//optional argument is set to true. The list will contain only valid servers if the "mustBeValid" argument is set to true. If the "sort" optional
//argument is set to true, then the list will be sorted alphabetically. If the "includeDuplicates" optional argument is set to false, then duplicate
//servers will appear only once in the list. By default, the "mustBeEnabled" and the "mustBeValid" arguments have the value false, while the "sort"
//and "includeDuplicates" arguments have the value true.
var serverNames = plugins.maintenance.getServerNames();
application.output("There are " + serverNames.length + " servers.");
for (var i=0; i<serverNames.length; i++)
	application.output("Server " + i + ": " + serverNames[i]);
```

### isInMaintenanceMode()

Returns true if the server is in maintenance mode, false otherwise.

**Returns:** [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) true if the server is currently in maintenance mode; false otherwise.

**Sample**

```js
// WARNING: maintenance plugin is only meant to run during solution import using before or after import hook(so not from client)
//Returns true if the server is in maintenance mode, false otherwise.
if (plugins.maintenance.isInMaintenanceMode())
	application.output("Server is in maintenance mode.");
else
	application.output("Server is not in maintenance mode.");
```

### setMaintenanceMode(maintenanceMode)

Puts the server into/out of maintenance mode, depending on the boolean parameter that is specified (if the parameter is true, then the server will be put into maintenance mode; if the parameter is false, then the server will be put out of maintenance mode).

**Parameters**

* [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) **maintenanceMode** ;

**Returns:** void

**Sample**

```js
// WARNING: maintenance plugin is only meant to run during solution import using before or after import hook(so not from client)
//Puts the server into/out of maintenance mode, depending on the boolean parameter that is specified (if the parameter is true, then the server will be put into maintenance mode; if the parameter is false, then the server will be put out of maintenance mode).
plugins.maintenance.setMaintenanceMode(!plugins.maintenance.isInMaintenanceMode());
```

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.servoy.com/reference/servoyextensions/server-plugins/maintenance.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
