Editing User Guide/Operations on Containers

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 464: Line 464:
  
 
== Running Commands in Container ==
 
== Running Commands in Container ==
 
Usually, a Container administrator logs in to the Container via network and executes any commands in the Container as on any other Linux box. However, you might need to execute commands inside Containers bypassing the normal login sequence. This can be helpful if:
 
 
* You do not know the Container login information, and you need to run some diagnosis commands inside the Container in order to verify that it is operational.
 
* Network access is absent for a Container. For example, the Container administrator might have accidentally applied incorrect firewalling rules or stopped the SSH daemon.
 
 
The OpenVZ software allows you to execute commands in a Container in these cases. Use the <code>vzctl exec</code> command for running a command inside the Container with the given ID. The session below illustrates the situation when the SSH daemon is not started:
 
 
# '''vzctl exec 103 /etc/init.d/sshd status'''
 
openssh-daemon is stopped
 
# '''vzctl exec 103 /etc/init.d/sshd start'''
 
Starting sshd: [  OK  ]
 
# '''vzctl exec 103 /etc/init.d/sshd status'''
 
openssh-daemon (pid  9899) is running...
 
 
Now Container users can log in to the Container via SSH (assuming that networking and firewall are not misconfigured).
 
 
When executing commands inside a Container from shell scripts, use the <code>vzctl exec2</code> command. It has the same syntax as <code>vzctl exec</code> but returns the exit code of the command being executed instead of the exit code of <code>vzctl</code> itself. You can check the exit code to find out whether the command has completed successfully.
 
 
If you wish to execute a command in all running Containers, you can use the following script:
 
 
# '''for CT in $(vzlist -H -o ctid); do echo "== CT $CT =="; vzctl exec $CT ''command''; done'''
 
 
where ''<code>command</code>'' is the command to be executed in all the running Containers. For example:
 
 
# '''for CT in $(vzlist -H -o ctid); do echo "== CT $CT =="; vzctl exec $CT uptime; done'''
 
== CT 103 ==
 
  15:17:19 up 13 min,  0 users,  load average: 0.00, 0.00, 0.00
 
== CT 123123123 ==
 
  15:17:19 up 22:00,  0 users,  load average: 0.00, 0.00, 0.00
 
  
 
<noinclude>{{UG/Footer}}</noinclude>
 
<noinclude>{{UG/Footer}}</noinclude>

Please note that all contributions to OpenVZ Virtuozzo Containers Wiki may be edited, altered, or removed by other contributors. If you don't want your writing to be edited mercilessly, then don't submit it here.
If you are going to add external links to an article, read the External links policy first!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)