cloud-init service failed to start with FileExistsError: [Errno 17] File exists: '/var/lib/cloud/data'
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
cloud-init |
Invalid
|
Undecided
|
Unassigned |
Bug Description
When I restart cloud-init in a loop with the following script, I get the error as mentioned in summary.
#Start of test script
#!/bin/bash
set -e
for i in {1..30}; do
echo -n "$i "
cloud-init clean -ls
sleep 1
systemctl restart cloud-*.service
done
echo ""
#End of test script
This is observed after applying fix: https:/
Error message is:
```
Jun 23 18:37:23 phdev cloud-init[2240]: Traceback (most recent call last):
Jun 23 18:37:23 phdev cloud-init[2240]: File "/usr/bin/
Jun 23 18:37:23 phdev cloud-init[2240]: load_entry_
Jun 23 18:37:23 phdev cloud-init[2240]: File "/usr/lib/
Jun 23 18:37:23 phdev cloud-init[2240]: get_uptime=True, func=functor, args=(name, args))
Jun 23 18:37:23 phdev cloud-init[2240]: File "/usr/lib/
Jun 23 18:37:23 phdev cloud-init[2240]: ret = func(*args, **kwargs)
Jun 23 18:37:23 phdev cloud-init[2240]: File "/usr/lib/
Jun 23 18:37:23 phdev cloud-init[2240]: util.ensure_
Jun 23 18:37:23 phdev cloud-init[2240]: File "/usr/lib/
Jun 23 18:37:23 phdev cloud-init[2240]: ensure_dir(d, mode)
Jun 23 18:37:23 phdev cloud-init[2240]: File "/usr/lib/
Jun 23 18:37:23 phdev cloud-init[2240]: os.makedirs(path)
Jun 23 18:37:23 phdev cloud-init[2240]: File "/usr/lib/
Jun 23 18:37:23 phdev cloud-init[2240]: mkdir(name, mode)
Jun 23 18:37:23 phdev cloud-init[2240]: FileExistsError: [Errno 17] File exists: '/var/lib/
Jun 23 18:37:23 phdev systemd[1]: cloud-init.service: Main process exited, code=exited, status=1/FAILURE
Jun 23 18:37:23 phdev systemd[1]: cloud-init.service: Failed with result 'exit-code'.
Jun 23 18:37:23 phdev systemd[1]: Failed to start Initial cloud-init job (metadata service crawler).
```
Find the attached for the log tarball.
Hi Shreenidhi,
I think we discussed previously that `systemctl restart` may not restart the specified services in the same order that they would be executed in boot. So it isn't clear to me that this is a bug in cloud-init; it may just be a bug in your reproducer.
Also, looking at the log, I see:
2020-06-23 18:37:25,535 - util.py[DEBUG]: Failed to write boot finished file /var/lib/ cloud/instance/ boot-finished python3. 7/site- packages/ cloudinit/ config/ cc_final_ message. py", line 81, in handle write_file( boot_fin_ fn, contents, ensure_ dir_exists= False)
Traceback (most recent call last):
File "/usr/lib/
util.
TypeError: write_file() got an unexpected keyword argument 'ensure_dir_exists'
which suggests that you only partially applied the patch.
If you see this issue during boot (or you find a more robust reproducer), please do run `cloud-init collect-logs` on an affected instance, attach the tarball here and move this bug back to New.
Thanks!
Dan