Previous page

Next page

Locate page in Contents

Print this page

Adding Custom Action Scripts

ContainerVirtuozzo allows you to write and execute your own scripts on the Hardware Node to do additional actions when certain Container-related operations are performed. There are two kinds of scripts you can specify for execution on the Node or in the Container context:

The names of all possible scripts that may be specified for executing before or after performing an operation are listed in the table below:

Script Name

Description

vz-precreate.<ext>

This script is to be run before the Container creation.

vz-postcreate.<ext>

This script is to be run after the Container creation.

vz-premount.<ext>

This script is to be run before mounting the Container private area.

vz-postmount.<ext>

This script is to be run after mounting the Container private area.

vz-preunmount.<ext>

This script is to be run before unmounting the Container private area.

vz-postmount.<ext>

This script is to be run after unmounting the Container private area.

vz-prestart.<ext>

This script is to be run before the Container start.

vz-poststart.<ext>

This script is to be run after the Container start.

vz-prestop.<ext>

This script is to be run before stopping the Container.

vz-poststop.<ext>

This script is to be run after stopping the Container.

vz-preclone.<ext>

This script is to be run before copying the Container.

vz-postclone.<ext>

This script is to be run after copying the Container.

vz-prechangevpsid.<ext>

This script is to be run before changing the Container ID.

vz-postchangevpsid.<ext>

This script is to be run after changing the Container ID.

Note: All the scripts are executed in the Host OS context.

You may specify scripts that will be applied to all Containers residing on the Hardware Node. To this effect, you should place your script to the C:\vz\Scripts\. In its turn, locating a script to the C:\vz\private\CT_ID\scripts\ directory allows you to set this script for executing in the given Container only (per-Container script). In the latter case, you may need to create the C:\vz\private\CT_ID\scripts\ directory manually since it is not created by creating a Container. When executed, any script takes only one parameter - the ID of the corresponding Container.

Note: During the Virtuozzo Containers installation, the Scripts subdirectory is automatically created in the directory you specified for storing all Container configuration files. By default, the C:\vz\ directory is used. However, you might have defined another path for the directory.

Let us assume you have created Container 101 with the private area located in the C:\vz\Private\101\ directory. And now you wish to write a script that will be executed each time after the Container start and display the number of events currently recorded in the Container System event log. To this effect, you should open Notepad or another text editor and write the following script code:

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colLogFiles = objWMIService.ExecQuery _

("Select * from Win32_NTEventLogFile where LogFileName='System'")

For Each objLogFile in colLogFiles

Wscript.Echo objLogFile.NumberOfRecords

Next

After that, you should save the file with the vz-poststart.vbs name, create the scripts subdirectory in the C:\vz\Private\101\ directory, and place your script to this subdirectory. Make sure that the full path of the script is C:\vz\Private\101\scripts\vz-poststart.vbs. From this point on, the vz-poststart.vbs script will be executed every time you start Container 101.

Note: By default, Virtuozzo is shipped with the vz-poststart.cmd script located in the C:\vz\Scripts\ directory. This script is needed for all Containers residing on the Hardware Node to perform certain operations necessary for Container error-free functioning. However, specifying your own per-Container scripts (i.e. scripts in the C:\vz\private\CT_ID\scripts\ directory) prevents the vz-poststart.cmd script from running. Therefore, you should make sure that each of your per-Container scripts calls the C:\vz\Scripts\vz-poststart.cmd script.

Please send us your feedback on this help page