Skip to content

Commit

Permalink
Improve vagrant provisioner resiliency (home-assistant#2252)
Browse files Browse the repository at this point in the history
This should make it easier to fix race conditions that might arise if
box is destroyed but setup_done placeholder file is not removed
properly
  • Loading branch information
Alexander Fortin authored and balloob committed Jun 7, 2016
1 parent e29459a commit fff413e
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions virtualization/vagrant/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ HASS running => http://localhost:8123/
'
}

setup_error() {
echo '############################################################
Something is off... maybe setup did not complete properly?
Please ensure setup did run correctly at least once.
To run setup again:
`rm setup_done; vagrant provision`
############################################################'
exit 1
}

setup() {
local hass_path='/root/venv/bin/hass'
local systemd_bin_path='/usr/bin/hass'
Expand All @@ -63,7 +76,9 @@ setup() {
}

run_tests() {
systemctl stop home-assistant
if ! systemctl stop home-assistant; then
setup_error
fi
source ~/venv/bin/activate
rsync -a --delete \
--exclude='*.tox' \
Expand All @@ -74,15 +89,19 @@ run_tests() {
}

restart() {
systemctl restart home-assistant
if ! systemctl restart home-assistant; then
setup_error
fi
rm $RESTART
}

main() {
if ! [ -f $SETUP_DONE ]; then setup; fi
if [ -f $RUN_TESTS ]; then run_tests; fi
if [ -f $RESTART ]; then restart; fi
systemctl start home-assistant
if ! systemctl start home-assistant; then
setup_error
fi
}

main

0 comments on commit fff413e

Please sign in to comment.