Skip to content

Commit

Permalink
Ensure we add a new line when appending to rc.local
Browse files Browse the repository at this point in the history
When we add content to rc.local, if the file already
exists then we need to make sure we add the content
after a new line explicitly

Fixes LP #1089668

Change-Id: I35be1496703b302f732363fa76ce832505eed599
(cherry picked from commit f393a51)
  • Loading branch information
Davanum Srinivas authored and vishvananda committed Feb 27, 2013
1 parent d5e7f55 commit 8289d6c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion nova/virt/disk/api.py
Expand Up @@ -415,11 +415,14 @@ def _setup_selinux_for_keys(fs):
# and so to append there you'd need something like:
# utils.execute('sed', '-i', '${/^exit 0$/d}' rclocal, run_as_root=True)
restorecon = [
'#!/bin/sh\n',
'\n',
'# Added by Nova to ensure injected ssh keys have the right context\n',
'restorecon -RF /root/.ssh/ 2>/dev/null || :\n',
]

if not fs.has_file(rclocal):
restorecon.insert(0, '#!/bin/sh')

rclocal_rel = os.path.relpath(rclocal, fs)
_inject_file_into_fs(fs, rclocal_rel, ''.join(restorecon), append=True)
utils.execute('chmod', 'a+x', rclocal, run_as_root=True)
Expand Down

0 comments on commit 8289d6c

Please sign in to comment.