Previous page

Next page

Locate page in Contents

Print this page

Virtuozzo Action Scripts

There might be situations when you need to do additional actions when a particular Container is started or stopped. For example, if you want to be able to access the Host OS file system (or part of it) from Container 101, then you can bind mount it inside the Container manually from the Host OS. However, after you restart the Container, your mount disappears, and you should manually type the mount command again.

The Virtuozzo Containers software allows you to automate procedures like the above by using Virtuozzo action scripts. There are six action scripts defined in the current version of Virtuozzo Containers:

global mount

This script runs immediately after vzctl mounts the Container private area. The Container itself is not yet running and the script is running in the Host OS context.


This script runs immediately after the global mount script. The Container is still not running, and the scripts is called in the Host OS context.


After vzctl has started a Container, it runs the Container start script. The script is running already in the Container context.


This script runs before the Container is stopped, in the Container context.


After the Container has been already stopped, the umount script is executed, and the script runs in the Host OS context.

global umount

This script runs when vzctl is about to dismount the Container private area. It also runs in the Host OS context.

It is important to understand how vzctl handles exit codes of action scripts. If exit code is non-zero, then vzctl will try to undo the action for the mount and start scripts. In other words, if the start script returns an error, then vzctl will stop Container, and if one of the mount scripts fails, then vzctl will dismount the Container private area. Please note that in this case vzctl will not execute the stop and umount scripts at all.

Caution: When executing vzctl start, both mount and start scripts run. However, if the start script fails then neither stop nor umount scripts will run. As a result, vzctl might be unable to dismount the Container private area, if you set up additional mounts in the mount scripts and dismount them in the umount scripts.

The situation with the umount and stop scripts is similar. If a script returns an error, then the action will not be taken. Be careful since this allows to create Containers that are not stoppable by vzctl.

The global scripts are named vps.mount and vps.umount and located in the /etc/vz/conf directory on the Hardware Node. These scripts are called when any Container on the Node is started or stopped. So, you should include in these scripts those commands that are common for all Containers and leave Container-specific commands for the scripts belonging to a particular Container. Container-specific action scripts are located in the /vz/private/CT_ID/scripts directory and have the mount, start, stop, and umount names. For example, the scripts specific for Container 101 will have the following names:

Note: If you are going to use Virtuozzo actions scripts for Containers residing on Hardware Nodes running earlier versions of Virtuozzo (e.g. 3.0), you should name the action scripts <CT_ID>.mount, <CT_ID>.start, <CT_ID>.stop, <CT_ID>.umount and put them to the /etc/vz/conf directory on the corresponding Nodes.

For the mount and umount scripts, the environment passed is the standard environment of the parent (i.e. vzctl) with two additional variables: $VEID and $VE_CONFFILE. The first one holds the ID of the Container being mounted (started, stopped, dismounted), and the second one holds the full path to the Container configuration file. It is probably a bit redundant. Parallels introduced both variables for convenience. You can use the following fragment of the code in bash scripts to get access to additional Container information like $VE_PRIVATE or $VE_ROOT locations:

# This script sources Container configuration files in the same
# order as vzctl does

# if one of these files does not exist then something is
# really broken
[ -f /etc/sysconfig/vz ] || exit 1
[ -f $VE_CONFFILE ] || exit 1

# source both files. Note the order, it is important
. /etc/vz/vz.conf

The start and stop scripts are performed in the Container context. If these scripts call any external commands, these commands are taken from the Container itself. Also note that the start script runs before any Container tasks (including init), thus the /proc file system is not mounted inside the Container at this moment therefore, applications using an information from /proc may be not functional.

Please send us your feedback on this help page