Adding Event Handlers (Linux)

Let's, for example, create an event handler for the 'customer account creation' event. The handler will accept a customer's name and username in Plesk from environment variables. For simplicity, we will use a shell-script called that looks as follows:


echo "--------------" >> /tmp/event_handler.log

/bin/date >> /tmp/event_handler.log # information on the event date and time

/usr/bin/id >> /tmp/event_handler.log # information on the user, on behalf of which the script was executed (to ensure control)

echo "customer created" >> /tmp/event_handler.log # information on the created customer account

echo "name: ${NEW_CONTACT_NAME}" >> /tmp/event_handler.log # customer's name

echo "login: ${NEW_LOGIN_NAME}" >> /tmp/event_handler.log # customer's username in Plesk

echo "--------------" >> /tmp/event_handler.log

This script prints some information to a file so that we could control its execution (we cannot output information to stdout/stderr, as the script is executed in the background mode).

Note: We strongly recommend that you use shell script files to handle events. Although you can assign direct system commands, they might not work. For example, commands with output redirection operators < or > will not work.

Suppose that our script is located in the directory /plesk_installation_directory/bin (for instance). Let's register it by creating an event handler via the Administrative Panel:

  1. Go to Tools & Settings > Event Manager.
  2. Click Add Event Handler.
  3. Select the event, you wish to assign a handler to in the Event menu.
  4. Select the priority for handler execution, or specify a custom value. To do this, select custom in the Priority menu and type in the value.

    When assigning several handlers to a single event you can specify the handler execution sequence, setting different priorities (higher value corresponds to a higher priority).

  5. Select the system user, on behalf of which the handler will be executed ("root" user, for example).
  6. In the Command input field, specify a command to be executed upon the selected event. In our example it is /usr/local/psa/bin/
  7. Click OK.

Note: In the script, we have specified the variables $NEW_CONTACT_NAME and $NEW_LOGIN_NAME. During execution of the handler, they will be replaced with name and username of the created user account respectively. The entire list of available variables is provided in Event Parameters Passed by Event Handlers.

Now if you log in to your Plesk and create a customer account, specifying the value 'Some Customer' in the Contact name field, and 'some_customer' in the field Login, the handler will be invoked, and the following records will be added to the /tmp/event_handler.log:

Fri Mar 16 15:57:25 NOVT 2007

uid=0(root) gid=0(root) groups=0(root)

customer created

name: Some Customer

login: some_customer

If you want to specify one or few handlers more, repeat the actions above for another handler.