From 44ec6b056e97a0067fb2656c9b1e4cad1ede03e4 Mon Sep 17 00:00:00 2001 From: Alexander Fortin Date: Thu, 2 Mar 2017 08:15:30 +0100 Subject: [PATCH] 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 --- virtualization/vagrant/Vagrantfile | 6 +- .../vagrant/home-assistant@.service | 20 +++++++ virtualization/vagrant/provision.sh | 58 +++++++++++-------- virtualization/vagrant/run_tests | 0 4 files changed, 59 insertions(+), 25 deletions(-) create mode 100644 virtualization/vagrant/home-assistant@.service mode change 100644 => 100755 virtualization/vagrant/provision.sh delete mode 100644 virtualization/vagrant/run_tests diff --git a/virtualization/vagrant/Vagrantfile b/virtualization/vagrant/Vagrantfile index 7c67baa2ce4..21d5bd04adc 100644 --- a/virtualization/vagrant/Vagrantfile +++ b/virtualization/vagrant/Vagrantfile @@ -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 diff --git a/virtualization/vagrant/home-assistant@.service b/virtualization/vagrant/home-assistant@.service new file mode 100644 index 00000000000..8e520952db9 --- /dev/null +++ b/virtualization/vagrant/home-assistant@.service @@ -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 diff --git a/virtualization/vagrant/provision.sh b/virtualization/vagrant/provision.sh old mode 100644 new mode 100755 index 69414cb9200..da5d48c6f18 --- a/virtualization/vagrant/provision.sh +++ b/virtualization/vagrant/provision.sh @@ -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 $* diff --git a/virtualization/vagrant/run_tests b/virtualization/vagrant/run_tests deleted file mode 100644 index e69de29bb2d..00000000000