256 Appendix A. Advanced Features
Adding Event Handlers
Let's, for example, create an event handler for the 'client account creation' event. The
handler will accept a client name and the client's login from environment variables. For
simplicity we will use a shell-script called test-handler.sh that looks as follows:
#!/bin/bash
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 "client created" >> /tmp/event_handler.log # information on
the created client account
echo "name: ${NEW_CONTACT_NAME}" >> /tmp/event_handler.log #
client's name
echo "login: ${NEW_LOGIN_NAME}" >> /tmp/event_handler.log #
client's login
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).
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 control panel:
1 Select the Server shortcut in the navigation pane.
2 Click the Event Manager icon in the Control Panel group.
3 Click the Add New Event Handler icon. The event handler setup page
appears.
4 Select the event, you wish to assign a handler to in the Event menu.
5 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).
6 Select the system user, on behalf of which the handler will be
executed ("root" user, for example).