Update Vagrant provision.sh (#6236)

- Bugfix: with f63a79ee we removed `script/home-assistant@.service`
  systemd unit file, which is used by Vagrant box to start/stop hass
- simplify interaction with Vagrant, provision.sh now is the only
  entry point and doesn't need the user to touch/remove files in
  order to change provisioner behavior
This commit is contained in:
Alexander Fortin 2017-03-02 08:15:30 +01:00 committed by Paulus Schoutsen
parent 354007f265
commit 44ec6b056e
4 changed files with 59 additions and 25 deletions

View File

@ -6,7 +6,11 @@ Vagrant.configure(2) do |config|
config.vm.synced_folder "../../", "/home-assistant"
config.vm.synced_folder "./config", "/root/.homeassistant"
config.vm.network "forwarded_port", guest: 8123, host: 8123
config.vm.provision "shell" do |shell|
config.vm.provision "fix-no-tty", type: "shell" do |shell|
shell.path = "provision.sh"
end
config.vm.provider :virtualbox do |vb|
vb.cpus = 2
vb.customize ['modifyvm', :id, '--memory', '1024']
end
end

View File

@ -0,0 +1,20 @@
# This is a simple service file for systems with systemd to tun HA as user.
#
# For details please check https://home-assistant.io/getting-started/autostart/
#
[Unit]
Description=Home Assistant for %i
After=network.target
[Service]
Type=simple
User=%i
# Enable the following line if you get network-related HA errors during boot
#ExecStartPre=/usr/bin/sleep 60
# Use `whereis hass` to determine the path of hass
ExecStart=/usr/bin/hass --runner
SendSIGKILL=no
RestartForceExitStatus=100
[Install]
WantedBy=multi-user.target

58
virtualization/vagrant/provision.sh Normal file → Executable file
View File

@ -7,30 +7,21 @@ readonly RESTART='/home-assistant/virtualization/vagrant/restart'
usage() {
echo '############################################################
############################################################
############################################################
Use `vagrant provision` to either run tests or restart HASS:
Use `./provision.sh` to interact with HASS. E.g:
`touch run_tests && vagrant provision`
- setup the environment: `./provision.sh start`
- restart HASS process: `./provision.sh restart`
- run test suit: `./provision.sh tests`
- destroy the host and start anew: `./provision.sh recreate`
or
Official documentation at https://home-assistant.io/docs/installation/vagrant/
`touch restart && vagrant provision`
To destroy the host and start anew:
`vagrant destroy -f ; rm setup_done; vagrant up`
############################################################
############################################################
############################################################'
}
print_done() {
echo '############################################################
############################################################
############################################################
HASS running => http://localhost:8123/
@ -43,9 +34,7 @@ setup_error() {
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`
To run setup again: `./provision.sh setup`
############################################################'
exit 1
@ -55,13 +44,14 @@ setup() {
local hass_path='/root/venv/bin/hass'
local systemd_bin_path='/usr/bin/hass'
# Setup systemd
cp /home-assistant/script/home-assistant@.service \
cp /home-assistant/virtualization/vagrant/home-assistant@.service \
/etc/systemd/system/home-assistant.service
systemctl --system daemon-reload
systemctl enable home-assistant
systemctl stop home-assistant
# Install packages
apt-get update
apt-get install -y git rsync python3-dev python3-pip
apt-get install -y git rsync python3-dev python3-pip libssl-dev libffi-dev
pip3 install --upgrade virtualenv
virtualenv ~/venv
source ~/venv/bin/activate
@ -76,6 +66,9 @@ setup() {
}
run_tests() {
rm -f $RUN_TESTS
echo '############################################################'
echo; echo "Running test suite, hang on..."; echo; echo
if ! systemctl stop home-assistant; then
setup_error
fi
@ -84,24 +77,41 @@ run_tests() {
--exclude='*.tox' \
--exclude='*.git' \
/home-assistant/ /home-assistant-tests/
cd /home-assistant-tests && tox
rm $RUN_TESTS
cd /home-assistant-tests && tox || true
echo '############################################################'
}
restart() {
echo "Restarting Home Assistant..."
if ! systemctl restart home-assistant; then
setup_error
else
echo "done"
fi
rm $RESTART
}
main() {
# If a parameter is provided, we assume it's the user interacting
# with the provider script...
case $1 in
"setup") rm -f setup_done; vagrant up --provision && touch setup_done; exit ;;
"tests") touch run_tests; vagrant provision ; exit ;;
"restart") touch restart; vagrant provision ; exit ;;
"start") vagrant up --provision ; exit ;;
"stop") vagrant halt ; exit ;;
"destroy") vagrant destroy -f ; exit ;;
"recreate") rm -f setup_done restart; vagrant destroy -f; \
vagrant up --provision; exit ;;
esac
# ...otherwise we assume it's the Vagrant provisioner
if [ $(hostname) != "contrib-jessie" ]; then usage; exit; fi
if ! [ -f $SETUP_DONE ]; then setup; fi
if [ -f $RUN_TESTS ]; then run_tests; fi
if [ -f $RESTART ]; then restart; fi
if [ -f $RUN_TESTS ]; then run_tests; fi
if ! systemctl start home-assistant; then
setup_error
fi
}
main
main $*