Execute Script on HN after VM Start [message #38992] |
Sat, 27 February 2010 19:00 |
bigbohne
Messages: 3 Registered: February 2010
|
Junior Member |
|
|
Hi there,
I've got a little problem that's driving me crazy.
Does someone of you know how to start a script in the hostnodes context AFTER the VM is up an running.
"<VEID>.mounts" - is executed before the vm starts in HN context
"<VEID>.start" - is executed after the vm stared. But in VM context.
My specs:
Debian Lenny
Kernel: 2.6.26-2-openvz-686
vzctl version 3.0.22
Thanks for any help!
Bigbohne
|
|
|
|
|
|
|
|
Re: Execute Script on HN after VM Start [message #39027 is a reply to message #38992] |
Thu, 04 March 2010 12:22 |
TheStig
Messages: 94 Registered: December 2008
|
Member |
|
|
let me save you the trouble:
/etc/vz/conf/103.mount
#!/bin/bash
. /etc/vz/start_script/103.sh &
disown
exit 0
/etc/vz/start_stript/103.sh
#!/bin/bash
_sleep() {
sleep 4
status=(`/usr/sbin/vzctl status 103`)
x=1
until [ $x == 6 ] ; do
sleep 1
if [ ${status[4]} == "running" ] ; then
CMD
MORE CMD
exit 0
else
x=`expr $x + 1`
fi
done
}
_sleep
The latter would wait once for five seconds and then try it again every second for five times.
Alternatively, if you want to wait forever, use
#!/bin/bash
sleep 5
_sleep() {
status=(`/usr/sbin/vzctl status 103`)
if [ ${status[4]} == "running" ] ; then
CMD
MORE CMD
exit 0
fi
sleep 1
_sleep
}
_sleep
[Updated on: Thu, 04 March 2010 12:23] Report message to a moderator
|
|
|
|
Re: Execute Script on HN after VM Start [message #39029 is a reply to message #38992] |
Thu, 04 March 2010 15:53 |
TheStig
Messages: 94 Registered: December 2008
|
Member |
|
|
if you think somebody else could need that piece of bashscript feel free to amend the wiki.
beware: the "disown" command is afaik absolutely necessary. otherwise vzctl won't resume the start command until the secondary script finished exec.
|
|
|