Open main menu

OpenVZ Virtuozzo Containers Wiki β

Changes

ExecuteInAllVEs

44 bytes added, 15:23, 6 January 2008
no edit summary
I found myself often faced with a need to run the same command in all VEs, e.g. ''apachectl restart'' to restart all webservers or ''dmesg | tail'' to see the latest news from everybody. This simple utility is just a loop around ''vzctl exec'' but I find it very handy.
You can loop through all VEs and execute this this easily:
<code>
for veid in `vzlist -Hoveid`; do vzctl exec $veid COMMAND; done
</code>
 
Knowing this, you can also save some typing later by making a simple utility out of it.
I like to call this ''/usr/sbin/vzexec'' so I can later just say ''vzexec apachectl restart''
<code>
#!/bin/bash
# vzexec -- execute a command on all VEs
CONFDIR="/etc/vz/conf"
if [ "$1" == "" ]; then
echo "$0 -- Execute a command on all VEs"
exit
fi
for veconf veid in $CONFDIR/*.conf ; do veid=`basename $veconf .confvzlist -Hoveid` if [ "$veid" == "0" ]; then continue; fi vename=`grep ^NAME $veconf | head -1 | sed -e 's@NAME=@@' | sed -e 's@"@@g'`do echo "*** VE $veid ($vename)"
vzctl exec $veid $@
done
</code>
24
edits