Child pages
  • Maintenance Mode
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 42 Next »

Advanced Features Related to Servoy Server Administration and Solution Import

Maintenance Mode

Maintenance mode is a special mode of operating Servoy Server. While Servoy Server is in maintenance mode, no new clients can connect to it. This is useful when performing certain administrative tasks, like solution imports.

In order to put Servoy Server into maintenance mode, you need to access the Servoy Server Admin Page. There you will find a button which says "Enter Maintenance Mode". If you push that button you will be asked to confirm that you really want to put Servoy Server into maintenance mode. If you confirm, then the Server will enter maintenance mode.

While in maintenance mode, the above mentioned button will have its text changed to "Exit Maintenance Mode". If you push the button, you will be again asked for confirmation. If you confirm the action, then the Server will be brought out of maintenance mode.

You can programmatically put the Server into maintenance mode, or bring it out of maintenance mode, by using the maintenance plugin. Please refer to the maintenance plugin API documentation for details about how to do that.

Solution Import Hooks

During solution import from the Servoy Admin Page, modules with certain name patterns are handled in a special way. Modules whose names start with "before_import" are handled as pre-import hooks. Their onOpen event handlers are executed before the solution is actually imported. Similarly, modules whose names start with "after_import" are handled as post-import hooks. Their onOpen event handles are executed after the solution is actually imported.

If you have several modules that start with "before_import" or "after_import", they will be all handled in this way, but no handling order is guaranteed. It is recommended that you have at most one pre-import and at most one post-import hook in your exported solutions.

During the execution of the onOpen event handlers from the pre-import and post-import hooks, any output printed with application.output will be redirected to the import log, which you can see in the Servoy Admin Page.

A simple example

Suppose you have a solution called "sample_01", with two modules called "before_sample_01" and "after_import_01". The "before_sample_01" module has the following onOpen event handler:

function onBeforeImportSolutionOpen()
{
	application.output("Method executed before solution import.");
}

The "after_import_01" module has the following onOpen event handler:

function onAfterImportSolutionOpen()
{
	application.output("Method executed after solution import.");
}

If you export this solution together with its two modules, and then you import it through the Servoy Admin Page, in the import log you should see the lines

[info]	Executing pre-import hook module 'before_import_01'.
[info]	Method executed before solution import.

before any message related to the actual solution import, and also you should see the lines

[info]	Executing post-import hook module 'after_import_01'.
[info]	Method executed after solution import.

after all messages related to the actual solution import.

What else can you do? The maintenance plugin.

The pre-import and post-import hooks were introduced for allowing you to automatically perform administrative tasks on the server while importing solutions:

  • Send messages to connected clients, or even kill connected clients.
  • Put the server into maintenance mode for the duration of the solution import.
  • Perform operations on databases.

These operations can be performed through the maintenance plugin, which is available since version 4.2 of Servoy. The maintenance plugin was designed specifically for being used with solution import hooks. Please consult its API documentation for specific details about available functions.

A typical scenario of using the solution import hooks is the following:

  • Before importing the solution, connected clients are notified that an import will take place, then they are disconnected and then the server is put into maintenance mode, so that no new clients can connect during the import.
  • The import is performed as usually.
  • After the import is over, the server is taken out of maintenance mode, so that clients can connect again.

All these steps can be automated if you create a pre-import and a post-import hook module. The pre-import hook module can have the following function set as its onOpen event handler:

function onBeforeImportSolutionOpen()
{
	application.output("Notifying and disconnecting connected clients...");
	plugins.maintenance.sendMessageToAllClients("A solution upgrade will take place on the server. You will be disconnected in 2 minutes.");
	application.sleep(2 * 60 * 1000);
	plugins.maintenance.sendMessageToAllClients("A solution upgrade will take place on the server. You will be disconnected NOW.");
	plugins.maintenance.shutDownAllClients();
	application.output("Putting server into maintenance mode...");
	plugins.maintenance.setMaintenanceMode(true);
	application.output("Proceeding to import...");
}

The function sends a notification to all connected clients, telling them that in two minutes (or any other amount of time that should be enough for clients to save any important data) they will be disconnected. The function waits for two minutes, then it sends another message to the clients, telling them that they will be immediately disconnected. Then all connected clients are killed and then the Server is put into maintenance mode. From this moment on, no new client will be able to connect to the Server.

The post-import hook module can have the following function as its onOpen event handler:

function onAfterImportSolutionOpen()
{
	application.output("Taking server out of maintenance mode.");
	plugins.maintenance.setMaintenanceMode(false);
	application.output("Clients can now connect to the server.");
}

This function takes the Server out of maintenance mode, so that clients can again connect to it.

  • No labels