cloud-init icon indicating copy to clipboard operation
cloud-init copied to clipboard

cloud-init clean should persist custom scripts subdirs

Open ubuntu-server-builder opened this issue 2 years ago • 1 comments

This bug was originally filed in Launchpad as LP: #1788961

Launchpad details
affected_projects = []
assignee = chad.smith
assignee_name = Chad Smith
date_closed = None
date_created = 2018-08-24T23:00:36.494065+00:00
date_fix_committed = None
date_fix_released = None
id = 1788961
importance = medium
is_complete = False
lp_url = https://bugs.launchpad.net/cloud-init/+bug/1788961
milestone = None
owner = chad.smith
owner_name = Chad Smith
private = False
status = triaged
submitter = chad.smith
submitter_name = Chad Smith
tags = []
duplicates = []

Launchpad user Chad Smith(chad.smith) wrote on 2018-08-24T23:00:36.494065+00:00

Some images contain custom scripts that we need to preserve across 'cloud-init clean' calls.

ubuntu-server-builder avatar May 11 '23 15:05 ubuntu-server-builder

We are also having similar issue in our corporate usage, we have multi-tier images like golden -> base -> app -> environment. We do need to have scripts that are saved into /var/lib/cloud/scripts/per-boot and yet they are deleted during cloud-init clean.

We are looking into https://cloudinit.readthedocs.io/en/latest/reference/custom_modules/custom_clean_scripts.html for solving the issue. But seem this will not preserve the files in /var/cloud content due to

https://github.com/canonical/cloud-init/blob/f696327d24a0b9a28da262b759afadce54e1a1b8/cloudinit/cmd/clean.py#L138C5-L148C21

for path in glob.glob("%s/*" % init.paths.cloud_dir):
        if path == seed_path and not remove_seed:
            continue
        try:
            if os.path.isdir(path) and not is_link(path):
                del_dir(path)
            else:
                del_file(path)
        except OSError as e:
            log_util.error("Could not remove {0}: {1}".format(path, str(e)))
            return 1

yunarta avatar Mar 07 '25 08:03 yunarta