How to unlock a container in OpenVZ
By Jithin on December 13th, 2016
In this tutorial we can check how to unlock a container in OpenVZ
OpenVZ is an operating system-level virtualization technology for Linux. It allows Multiple isolated operating system instances, called containers/Virtual Private Servers(VPS)/Virtual Environments(VE) to run on a single physical server.
There might be some situations when you need to perform additional actions when a container is started/stopped. You need OpenVZ action scripts to perform these additional operations to manage particular container. Action scripts are located in the /vz/private/CTID/scripts/ and /etc/vz/conf directories. There are both global and user defined scripts for containers. The global action scripts can be executed for all containers and user defined action scripts can be only run for a specific container identified by the container id(CTID). The vzctl has an ability to execute user-defined scripts when a specific vzctl command is run for a container. The vzctl command can execute action scripts like start, stop, restart, mount, and unmount.
—vzctl [flags] CTID –parameter value[…]
1) To start a container
—vzctl start CTID [–wait] [–force]
2) To stop a container
—vzctl stop CTID [–FAST]
3) To restart a container
—vzctl restart CTID [–fast] [–skip-unmount]
4) To know the current status of a container
—vzctl status CTID
where, start, stop, restart, status are the action scripts and the CTID is the Container ID.
The OpenVZ container fails to start and becomes unresponsive sometimes, if the action scripts does not work properly. Sometimes the container will get stuck or unresponsive when running time consuming processes like automated or manual virtuozo backups. At this stage the container will be unresponsive and is referred to be in a locked stage. While starting the OpenVZ container you will get an error like this
—[root@server ~]# vzctl stop CTID
—Container already locked
You won’t be able to start, stop, restart or run any action scripts on the container at the this stage.
Kill the process
If multiple failed attempts are made to start or restart the container, then every such event will have a separate process id(PID). You must remove all those pid and also the lock file. The pid can be found out by running the below command.
—ps aux | grep /usr/sbin/vzctl start CTID
—ps aux | grep /usr/sbin/vzctl restart CTID
You can kill the process by killing all those pid found from the above command. Run this command to kill the every founded pid.
—kill -9 pid
Delete the lock file
The lock file contains no data and exists as an empty marker file. It contains properties and settings for the lock. The lock file signals the applications that a resource should not be used until the lock is released. The default location of the lock file is
To release the resources and free the container from lock, this file must be deleted. Each container has its own specific lock file. To delete the lock file use the command given below.
—[root@server ~]# rm /vz/lock/CTID.lck
—rm : remove regular file ‘/vz/lock/CTID.lck’? y
Kill the checkpoint
Finally kill the checkpoint of the container to unlock and free the resources. The parameter –kill is used to kill the container checkpoint.
—[root@server ~]# vzctl chkpnt CTID –kill
Container is not running
Start the container
Once you have run all of them, you can re-run your container using vzctl start/restart/stop command.
If you need any further assistance please contact our support department.