Skip to content

Instantly share code, notes, and snippets.

@gretel
Last active April 4, 2019 08:55
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gretel/34008d667a8a243a9682e5207619ad95 to your computer and use it in GitHub Desktop.
Save gretel/34008d667a8a243a9682e5207619ad95 to your computer and use it in GitHub Desktop.
`vagrant` on `ubuntu-16.04` can get in conflict with *unattended-upgrade* running and locking the `dpkg` subsystem. this script waits gracefully
#!/usr/bin/env bash
# https://gist.github.com/gretel/34008d667a8a243a9682e5207619ad95
# 2016 tom hensel <github@jitter.eu>
# `vagrant` on `ubuntu-16.04` can get in conflict with *unattended-upgrade* running and locking the `dpkg` subsystem. this script waits gracefully
# in `Vagrantfile`:
# config.vm.provision 'Wait for unattended-upgrades', type: 'shell', path: './provisioning/wait_unattended_upgrades.sh', args: %w( dpkg apt unattended-upgrade )
#
function wait_procnames {
while true; do
alive_pids=()
for pname in "$@"; do
if [ "$(pgrep "$pname")" ]; then
alive_pids+=("$pname ")
fi
done
if [ "${#alive_pids[@]}" -eq 0 ]; then
break
else
printf "waiting for: %s\n" "${alive_pids[@]}"
fi
sleep 1
done
}
wait_procnames "$@"
@jasonhildebrand
Copy link

jasonhildebrand commented May 19, 2016

Thanks for this. I found that passing the procnames as a single quoted string didn't work - was being treated as a single process name and didn't ever match.

I changed the last line to remove the single quotes:

wait_procnames dpkg apt unattended-upgrade

@gretel
Copy link
Author

gretel commented Jun 9, 2016

@jasonhildebrand right, changed that, again. regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment