Event Handlers

Certain actions in Plesk, such as:

are recognized by Plesk as events. For every event, you can create one or more event handlers that execute a predetermined command every time the event occurs.

Event handlers are useful if you want a certain action or a set of actions to be carried out every time a specific event occurs. For example, you can create an event handler that triggers every time a subscription is created and configure it to automatically create a mailbox, send a request to an external service, and so on.

Next in this section:

Adding Event Handlers

Passing Event Parameters

Editing and Removing Event Handlers

Event Parameters Passed by Event Handlers


Adding Event Handlers

  1. Go to Tools & Settings > Event Manager.
  2. Click Add Event Handler.
  3. Select the event that will trigger the handler from the "Event" list.
  4. Under "Priority", set the handler execution priority by selecting it from the list or typing a custom number in the field. Priority becomes important if you assign several handlers to a single event. In this case, handlers are triggered according to their priority in descending order (the event triggers the handler with the highest priority first, the handler with the second highest priority next, and so on).
  5. Select the system user on whose behalf the handler will be executed from the "User" list.

    Note (Plesk for Linux): The server administrator can create the event handlers that will be run on the server on behalf of user root. If you wish to restrict usage of the root account, create an empty file with name root.event_handler.lock in the location /usr/local/psa/var/.

  6. Type the path to the shell script or a .bat file containing the commands to be executed whenever the event handler triggers in the "Command" field (for example, /usr/local/psa/bin/script.sh or C:\Windows\Temp\script.bat).

    Note (Plesk for Linux): Make sure to give your script the execute permission. You can do so by running the following command: chmod 755 <script.sh>

  7. Click OK.


Passing Event Parameters

Whenever an event handler triggers, it passes certain data ("Event Parameters") associated with the event (which data are passed depends on the event handler in question). For example, the "Domain created" event handler passes the following parameters:

Each parameter is passed as an environment variable that you can use in your shell script or .bat file as follows:

Plesk for Linux

Use the placeholder ${ENVIRONMENT_VARIABLE_NAME} (for example, "${NEW_DOMAIN_NAME}") in your shell script. When the event handler triggers, the placeholder will be replaced by the value corresponding to the event.

Plesk for Windows

Use the placeholder %N (for example, "%1") in your bat file, and append the name of the desired environment variable in the corresponding position at the end of the command in the event handler settings. In the following example


the placeholder "%1" will be replaced with the value of the "NEW_DOMAIN_NAME" environment variable, and the "%2" will be replaced with the value of "NEW_DOMAIN_GUID". If you use "%3" in the .bat file, it will not be replaced with anything, as only two environment variable names were specified after the command.

You can see the complete list of event parameters and associated environment variable names for each event handler here.

For reference, here are two examples of scripts for the ‘Customer account created’ event:

If you log in to Plesk and create a customer account with the name "John Doe" and login “john_doe”, the event handler will trigger and the following records will be added to the event_handler.log file:


Editing and Removing Event Handlers

To see the list of currently active event handlers, go to Tools & Settings > Event Manager. Here, you can also edit and remove event handlers: