diff options
author | Scott Moser <smoser@ubuntu.com> | 2010-02-19 01:54:49 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2010-02-19 01:54:49 -0500 |
commit | d24e24686e0aa40adbd2f31f29a61f02db838b00 (patch) | |
tree | bdb1d06025390d855fc5f3954edb09b73b205814 | |
parent | 433db020a1d7a3165053a0a13b0dda22086ac71b (diff) | |
download | vyos-cloud-init-d24e24686e0aa40adbd2f31f29a61f02db838b00.tar.gz vyos-cloud-init-d24e24686e0aa40adbd2f31f29a61f02db838b00.zip |
add "runcmd" support in CloudConfig
runcmd allows simple running of commands at rc.local like time frame
see doc/examples/cloud-config.txt for more info.
-rw-r--r-- | cloudinit/CloudConfig.py | 23 | ||||
-rw-r--r-- | doc/examples/cloud-config.txt | 18 |
2 files changed, 41 insertions, 0 deletions
diff --git a/cloudinit/CloudConfig.py b/cloudinit/CloudConfig.py index 674e868e..e15dbb2c 100644 --- a/cloudinit/CloudConfig.py +++ b/cloudinit/CloudConfig.py @@ -189,6 +189,7 @@ class CloudConfig(): def h_config_misc(self,name,args): handle_updates_check(self.cfg) + handle_runcmd(self.cfg) def h_config_puppet(self,name,args): # If there isn't a puppet key in the configuration don't do anything @@ -494,3 +495,25 @@ def handle_updates_check(cfg): except: warn("failed to enable cron update system check") +def handle_runcmd(cfg): + if not cfg.has_key("runcmd"): + return + outfile="%s/runcmd" % cloudinit.user_scripts_dir + + content="#!/bin/sh\n" + escaped="%s%s%s%s" % ( "'", '\\', "'", "'" ) + try: + for args in cfg["runcmd"]: + # if the item is a list, wrap all items in single tick + # if its not, then just write it directly + if isinstance(args,list): + fixed = [ ] + for f in args: + fixed.append("'%s'" % f.replace("'",escaped)) + content="%s%s\n" % ( content, ' '.join(fixed) ) + else: + content="%s%s\n" % ( content, args ) + + util.write_file(outfile,content,0700) + except: + warn("failed to open %s for runcmd", outfile) diff --git a/doc/examples/cloud-config.txt b/doc/examples/cloud-config.txt index f4de88e8..49ee7b26 100644 --- a/doc/examples/cloud-config.txt +++ b/doc/examples/cloud-config.txt @@ -155,3 +155,21 @@ ssh_keys: # default: false (service available) disable_ec2_metadata: true +# run commands +# default: none +# runcmd contains a list of either lists or a string +# each item will be executed in order at rc.local like level with +# output to the console +# - if the item is a list, the items will be properly executed as if +# passed to execve(3) (with the first arg as the command). +# - if the item is a string, it will be simply written to the file and +# will be interpreted by 'sh' +# +# Note, that the list has to be proper yaml, so you have to escape +# any characters yaml would eat (':' can be problematic) +runcmd: + - [ ls, -l, / ] + - [ sh, -xc, "echo $(date) ': hello world!'" ] + - [ sh, -c, echo "=========hello world'=========" ] + - ls -l /root + - [ wget, "http://slashdot.org", -O, /tmp/index.html ] |