summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2011-01-19 04:35:46 +0000
committerScott Moser <smoser@ubuntu.com>2011-01-19 04:35:46 +0000
commitb85106a10a78e4c15303ac3b9b16d03a3f2f9cab (patch)
tree97d3b765b5214c86e30144beee35fe10106282b2
parent548f5b3f81799f3339e66444be58f7016fa8c0a2 (diff)
downloadvyos-cloud-init-b85106a10a78e4c15303ac3b9b16d03a3f2f9cab.tar.gz
vyos-cloud-init-b85106a10a78e4c15303ac3b9b16d03a3f2f9cab.zip
move user scripts ('#!' and runcmd) to be per-instance (LP: #675711)
Previously, if you ran an instance with either runcmd data or user-data scripts, it would run again after rebundle or create-image. This puts the files created by runcmd or user-data scripts into instance-id specific paths, and then runs them by that instance-id specific path. LP: #675711
-rw-r--r--cloudinit/CloudConfig/cc_runcmd.py3
-rw-r--r--cloudinit/__init__.py3
-rw-r--r--upstart/cloud-run-user-script.conf10
3 files changed, 10 insertions, 6 deletions
diff --git a/cloudinit/CloudConfig/cc_runcmd.py b/cloudinit/CloudConfig/cc_runcmd.py
index 97d21900..969f6394 100644
--- a/cloudinit/CloudConfig/cc_runcmd.py
+++ b/cloudinit/CloudConfig/cc_runcmd.py
@@ -21,7 +21,8 @@ import cloudinit.util as util
def handle(name,cfg,cloud,log,args):
if not cfg.has_key("runcmd"):
return
- outfile="%s/runcmd" % cloudinit.user_scripts_dir
+ outfile="%s/%s/runcmd" % \
+ (cloudinit.user_scripts_dir, cloud.get_instance_id())
content="#!/bin/sh\n"
escaped="%s%s%s%s" % ( "'", '\\', "'", "'" )
diff --git a/cloudinit/__init__.py b/cloudinit/__init__.py
index fd20c7be..be366d4c 100644
--- a/cloudinit/__init__.py
+++ b/cloudinit/__init__.py
@@ -338,7 +338,8 @@ class CloudInit:
return
filename=filename.replace(os.sep,'_')
- util.write_file("%s/%s" % (user_scripts_dir,filename), payload, 0700)
+ util.write_file("%s/%s/%s" %
+ (user_scripts_dir,self.get_instance_id(),filename), payload, 0700)
def handle_upstart_job(self,data,ctype,filename,payload):
if ctype == "__end__" or ctype == "__begin__": return
diff --git a/upstart/cloud-run-user-script.conf b/upstart/cloud-run-user-script.conf
index e50006d4..9a47e57b 100644
--- a/upstart/cloud-run-user-script.conf
+++ b/upstart/cloud-run-user-script.conf
@@ -7,8 +7,10 @@ console output
task
script
-sdir=/var/lib/cloud/data/scripts
-[ -d "$sdir" ] || exit 0
-exec cloud-init-run-module once-per-instance user-scripts execute \
- run-parts --regex '.*' "$sdir"
+iid=$(cloud-init-query instance-id) || exit 1
+sdir="/var/lib/cloud/data/scripts/${iid}"
+if [ -d "$sdir" ]; then
+ exec cloud-init-run-module once-per-instance user-scripts execute \
+ run-parts --regex '.*' "$sdir"
+fi
end script