Skip to content

Commit

Permalink
move user scripts ('#!' and runcmd) to be per-instance (LP: #675711)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
smoser committed Jan 19, 2011
1 parent 548f5b3 commit b85106a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion cloudinit/CloudConfig/cc_runcmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
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" % ( "'", '\\', "'", "'" )
Expand Down
3 changes: 2 additions & 1 deletion cloudinit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ def handle_user_script(self,data,ctype,filename,payload):
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
Expand Down
10 changes: 6 additions & 4 deletions upstart/cloud-run-user-script.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b85106a

Please sign in to comment.