Robust Shell Scripts

david karapetyan on November 19, 2018

Today I wanted to set up a MySQL cluster with a leader and a replica using GTID replication. I copied some code I had for setting up consul clust... [Read Full]
markdown guide

Isn't "apt install --yes ruby" only supposed to run after the update? How can that line become concurrent ? 🤔


Exactly. The failure makes no sense but that's the failure in the cloud-init logs

pt[1451]: INFO startup-script: Building dependency tree...
pt[1451]: INFO startup-script: Reading state information...
pt[1451]: INFO startup-script: 2 packages can be upgraded. Run 'apt list --upgradable' to see them.
pt[1451]: INFO startup-script: + apt install --yes ruby
pt[1451]: INFO startup-script: WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
pt[1451]: INFO startup-script: E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavai
pt[1451]: INFO startup-script: E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another pro
pt[1451]: INFO startup-script: Return code 100.
pt[1451]: INFO Finished running startup scripts.
Started Google Compute Engine Startup Scripts.

I've mostly given up on trying to make sense of errors. If something is broken then I just brute force my way to a solution. In this case, additing the retry loop and forcing non-interactive mode for apt seemed to fix the random failures.


Usually I put an upper bound on loops but I'm almost certain this was an issue with cloud-init racing against some other service. I'm willing to risk the infinite loop in this case.

code of conduct - report abuse