sign in
Home | Updates | Pages | Users | Admin | Help

vtips

VServer Tips and Tricks

Bootstrap debian (sarge)

root% vserver sarge build -m debootstrap -- -d sarge -m http://ftp.jp.debian.org/debian/
Will create /sarge and will bootstrap debian sarge there.

Bind a service to given IP (interface)

# description: Wrapper to start httpd bound to a single IP
IP=eth0
exec /usr/sbin/chbind --ip $IP /etc/init.d/httpd $*

Commands observing ALL vservers

root% vps -ax
root% vpstree -ap
root% vtop
root% vuname -g --xid tol
All of these commands are simply wrappers which are actually doing:
root% chcontext --ctx 1 pstree $*
eg. chcontext—ctx ps auxw

Execution of commands with wild-cards

The trick is to use a shell on the other side (in the vserver). The command is simply rewritten like this:

root% /usr/sbin/vserver server exec /bin/sh -c "command *" 

Kill all processes in given context

Get the context CTX with vserver-stat:

root% vserver-stat
CTX   PROC    VSZ    RSS  userTIME   sysTIME    UPTIME NAME
0       79 127.9M  10.5K   1h44m14  24m15s41  23h14m47 root server
1151     9 164.9M   6.5K   0m00s54   0m00s46  12m42s24 sarge

Then kill those processes:

# for example: vkill --xid 1151 -s TERM
root% vkill --xid <xid> -s TERM
root% vkill --xid <xid> -s KILL

Update the ARP caches

When a virtual server is moved from one physical server to another, other network nodes will keep trying to contact the server on the old MAC address for the length of their arp-cache timeout. To update the ARP caches of other network notes (and so make your new server reachable), send a gratuitous ARP request like this:

root% arping -c 10 -S virtual.server.IP -B

That command will broadcast your new MAC address 10 times to the local network. Hopefully they will get the idea and your vserver will be reachable.!!!

Mount a dir from one vserver into another from the host

root% vnamespace -e <vserver> mount --rbind /directory/to/mount/somewhere /where/to/mount/it

Also you can edit /etc/vservers//fstab (gentoo-specific binding follows):

none    /proc           proc    defaults                0 0
none    /tmp            tmpfs   size=16m,mode=1777      0 0
none    /dev/pts        devpts  gid=5,mode=620          0 0
# Portage related dirs
/usr/distfiles    /usr/distfiles auto    rbind   0 0
/usr/portage      /usr/portage   auto    rbind   0 0
/usr/shadow       /usr/shadow    auto    rbind   0 0
/usr/vpackages    /usr/packages  auto    rbind   0 0

See also


Powered by JunebugWiki v0.0.31 Page last edited by stoyan on December 15, 2006 05:54 PM (diff)
[readonly] Version 2 (current) «olderversions