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:
This script runs immediately after
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.
This script runs before the Container is stopped, in the Container context.
After the Container has been already stopped, the
This script runs when
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
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
umount scripts at all.
Caution: When executing
vzctl start, both
start scripts run. However, if the
start script fails then neither
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
The situation with the
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
The global scripts are named
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
/scripts directory and have the
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
>.umount and put them to the
/etc/vz/conf directory on the corresponding Nodes.
umount scripts, the environment passed is the standard environment of the parent (i.e.
vzctl) with two additional variables:
VE. 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
# 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
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