[one-users] Run bash script in vm on spin-up
Pavel Tankov
pavel.tankov at strategyobject.com
Fri Nov 28 02:44:46 PST 2014
Hello Kerry,
I am having the same problem. I think I discovered why your test.sh
script doesn't get executed:
!!! Opennebula completely disregards the INIT_SCRIPTS="test.sh" entry in
your CONTEXT=[...] section of the template !!!
How to verify? After your VM spins up, login and mount the CONTEXT image
like so:
mount -t iso9660 /dev/sr0 /mnt
Enter /mnt and you will find your test.sh file there. So far so good.
There is one more file there - context.sh. You can see that it contains
the variables from your CONTEXT=[...] section of the template. You can
see that it contains an entry like FILES_DS='...' or
FILES='/var/lib/one/datastores/2/test.sh' that mentions your script.
HOWEVER, it does NOT contain an entry like INIT_SCRIPTS="test.sh". OK,
so now open /etc/one-context.d/99-execute-scripts. That script is
responsible for executing your custom scripts. Here it is:
#!/bin/bash
MOUNT_DIR=/mnt
TMP_DIR=/tmp/one-context-tmp
if [ -z "$INIT_SCRIPTS" ]; then
if [ -f "$MOUNT_DIR/init.sh" ]; then
INIT_SCRIPTS=init.sh
fi
fi
mkdir -p $TMP_DIR
cd $MOUNT_DIR
for f in $INIT_SCRIPTS; do
cp $f $TMP_DIR
chmod +x $TMP_DIR/$f
$TMP_DIR/$f
done
In the beginning it checks to see if there is an environment
variableINIT_SCRIPTS defined. It is never defined, no matter whether you
put INIT_SCRIPTS="test.sh" in your CONTEXT=[...] or not because, as it
seems, Opennebula silently disregards it. So, in that case the
99-execute-scripts script continues with the default, which is init.sh.
TL; DR;
Name your script init.sh and it will be executed.
Opennebula devs, please, fix this!
P.S.: Kerry, you say:
/> I have created "test.sh" and put it into the "files" datastore on the//head node./
Please, explain how you did it, because I can't seem to find a
step-by-step explanation about this in the documentation.
Thanks,
-- Pavel Tankov
On 12.09.2014 02:28, kerryhall . wrote:
> Hi Valentin,
>
> I appreciate the help! I managed to create a new CONTEXT image, which
> copied my test.sh to the datastore successfully, and I updated my
> template to include those two lines you specified.
>
> However, it looks like test.sh is not executing on vm spin up.
> Currently all it does is "touch /root/test.tmp" to confirm execution.
> However when I booted my vm, this file was not created. Also tried
> doing "useradd tmp" as well, with no luck. test.sh has executable flag
> set for user, group, and other. I also tried setting permissions of
> test.sh to 777, still no luck.
>
> Thanks!!
> Kerry
>
>
>
>
> On Mon, Sep 8, 2014 at 11:27 PM, Valentin Bud <valentin.bud at gmail.com
> <mailto:valentin.bud at gmail.com>> wrote:
>
> Hello Kerry,
>
> Do you have a registered image of type CONTEXT with the name of
> `test.sh`
> in the files datastore?
>
> The file you specify in FILES_DS can be found in the
> contextualization CDROM
> on the VM (/dev/disk/by-label/CONTEXT).
>
> The following would run a `test.sh` script when the VM is spun up
> at the end
> of the contextualization routine [1].
>
> CONTEXT = [
> FILES_DS="$FILE[IMAGE=\"test.sh\"]",
> INIT_SCRIPTS="test.sh",
> ...
> ]
>
> [1]:
> https://github.com/OpenNebula/addon-context-linux/blob/master/base/etc/one-context.d/99-execute-scripts
>
> Best,
> Valentin
>
>
> On Mon, Sep 8, 2014 at 11:09 PM, kerryhall . <kerryhall at gmail.com
> <mailto:kerryhall at gmail.com>> wrote:
>
> Thanks! I'm still having issues here unfortunately. I tried
> putting:
>
> FILES_DS="$FILE[IMAGE=\"test.sh\"]"
>
> into my template context section, but I get:
>
> "User 0 does not own an image with name: test.sh"
>
> I'm not trying to include an image, I just want test.sh (a
> file in my file datastore) to get copied to anywhere on my
> vm's filesystem. (And eventually, I want test.sh to get run on
> vm creation, or failing that, every time the vm starts)
>
> Thanks!!
>
> On Fri, Jul 25, 2014 at 11:18 PM, Valentin Bud
> <valentin.bud at gmail.com <mailto:valentin.bud at gmail.com>> wrote:
>
> Hello Kerry,
>
> Under "Defining Context" [1] there is an example how to
> use FILES_DS.
>
> FILES_DS="$FILE[IMAGE=\"test.sh\"]
>
> [1]:
> http://docs.opennebula.org/4.6/user/virtual_machine_setup/cong.html
>
> Best,
> Valentin
>
>
>
> On Fri, Jul 25, 2014 at 11:29 PM, kerryhall .
> <kerryhall at gmail.com <mailto:kerryhall at gmail.com>> wrote:
>
> Hi folks,
>
> I am trying to run a bash script on a vm as it gets
> spun up. I've read:
> http://docs.opennebula.org/4.6/user/virtual_machine_setup/cong.html
>
> but there isn't too much to go on there.
>
> I have created "test.sh" and put it into the "files"
> datastore on the head node.
>
> The issue I am having is that the syntax in the
> "Defining Context" section of
> http://docs.opennebula.org/4.6/user/virtual_machine_setup/cong.html
> is ambiguous, specifically the "files_ds" section. I
> have tried:
>
> FILES_DS="$FILE[\"test.sh\"]"
>
> and
> FILES_DS="/var/lib/one/datastores/2/test.sh"
>
> As a first step, I'm just trying to get this file
> included in my vm at all.
>
> Thanks!
> Kerry
>
>
> _______________________________________________
> Users mailing list
> Users at lists.opennebula.org
> <mailto:Users at lists.opennebula.org>
> http://lists.opennebula.org/listinfo.cgi/users-opennebula.org
>
>
>
>
>
>
>
> _______________________________________________
> Users mailing list
> Users at lists.opennebula.org
> http://lists.opennebula.org/listinfo.cgi/users-opennebula.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opennebula.org/pipermail/users-opennebula.org/attachments/20141128/7dd18ebf/attachment-0001.htm>
More information about the Users
mailing list