mirror of
https://github.com/home-assistant/core.git
synced 2025-07-12 15:57:06 +00:00
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:
parent
354007f265
commit
44ec6b056e
6
virtualization/vagrant/Vagrantfile
vendored
6
virtualization/vagrant/Vagrantfile
vendored
@ -6,7 +6,11 @@ Vagrant.configure(2) do |config|
|
|||||||
config.vm.synced_folder "../../", "/home-assistant"
|
config.vm.synced_folder "../../", "/home-assistant"
|
||||||
config.vm.synced_folder "./config", "/root/.homeassistant"
|
config.vm.synced_folder "./config", "/root/.homeassistant"
|
||||||
config.vm.network "forwarded_port", guest: 8123, host: 8123
|
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"
|
shell.path = "provision.sh"
|
||||||
end
|
end
|
||||||
|
config.vm.provider :virtualbox do |vb|
|
||||||
|
vb.cpus = 2
|
||||||
|
vb.customize ['modifyvm', :id, '--memory', '1024']
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
20
virtualization/vagrant/home-assistant@.service
Normal file
20
virtualization/vagrant/home-assistant@.service
Normal 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
58
virtualization/vagrant/provision.sh
Normal file → Executable file
@ -7,30 +7,21 @@ readonly RESTART='/home-assistant/virtualization/vagrant/restart'
|
|||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo '############################################################
|
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() {
|
print_done() {
|
||||||
echo '############################################################
|
echo '############################################################
|
||||||
############################################################
|
|
||||||
############################################################
|
|
||||||
|
|
||||||
|
|
||||||
HASS running => http://localhost:8123/
|
HASS running => http://localhost:8123/
|
||||||
@ -43,9 +34,7 @@ setup_error() {
|
|||||||
Something is off... maybe setup did not complete properly?
|
Something is off... maybe setup did not complete properly?
|
||||||
Please ensure setup did run correctly at least once.
|
Please ensure setup did run correctly at least once.
|
||||||
|
|
||||||
To run setup again:
|
To run setup again: `./provision.sh setup`
|
||||||
|
|
||||||
`rm setup_done; vagrant provision`
|
|
||||||
|
|
||||||
############################################################'
|
############################################################'
|
||||||
exit 1
|
exit 1
|
||||||
@ -55,13 +44,14 @@ setup() {
|
|||||||
local hass_path='/root/venv/bin/hass'
|
local hass_path='/root/venv/bin/hass'
|
||||||
local systemd_bin_path='/usr/bin/hass'
|
local systemd_bin_path='/usr/bin/hass'
|
||||||
# Setup systemd
|
# Setup systemd
|
||||||
cp /home-assistant/script/home-assistant@.service \
|
cp /home-assistant/virtualization/vagrant/home-assistant@.service \
|
||||||
/etc/systemd/system/home-assistant.service
|
/etc/systemd/system/home-assistant.service
|
||||||
systemctl --system daemon-reload
|
systemctl --system daemon-reload
|
||||||
systemctl enable home-assistant
|
systemctl enable home-assistant
|
||||||
|
systemctl stop home-assistant
|
||||||
# Install packages
|
# Install packages
|
||||||
apt-get update
|
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
|
pip3 install --upgrade virtualenv
|
||||||
virtualenv ~/venv
|
virtualenv ~/venv
|
||||||
source ~/venv/bin/activate
|
source ~/venv/bin/activate
|
||||||
@ -76,6 +66,9 @@ setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
run_tests() {
|
run_tests() {
|
||||||
|
rm -f $RUN_TESTS
|
||||||
|
echo '############################################################'
|
||||||
|
echo; echo "Running test suite, hang on..."; echo; echo
|
||||||
if ! systemctl stop home-assistant; then
|
if ! systemctl stop home-assistant; then
|
||||||
setup_error
|
setup_error
|
||||||
fi
|
fi
|
||||||
@ -84,24 +77,41 @@ run_tests() {
|
|||||||
--exclude='*.tox' \
|
--exclude='*.tox' \
|
||||||
--exclude='*.git' \
|
--exclude='*.git' \
|
||||||
/home-assistant/ /home-assistant-tests/
|
/home-assistant/ /home-assistant-tests/
|
||||||
cd /home-assistant-tests && tox
|
cd /home-assistant-tests && tox || true
|
||||||
rm $RUN_TESTS
|
echo '############################################################'
|
||||||
}
|
}
|
||||||
|
|
||||||
restart() {
|
restart() {
|
||||||
|
echo "Restarting Home Assistant..."
|
||||||
if ! systemctl restart home-assistant; then
|
if ! systemctl restart home-assistant; then
|
||||||
setup_error
|
setup_error
|
||||||
|
else
|
||||||
|
echo "done"
|
||||||
fi
|
fi
|
||||||
rm $RESTART
|
rm $RESTART
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
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 $SETUP_DONE ]; then setup; fi
|
||||||
if [ -f $RUN_TESTS ]; then run_tests; fi
|
|
||||||
if [ -f $RESTART ]; then restart; fi
|
if [ -f $RESTART ]; then restart; fi
|
||||||
|
if [ -f $RUN_TESTS ]; then run_tests; fi
|
||||||
if ! systemctl start home-assistant; then
|
if ! systemctl start home-assistant; then
|
||||||
setup_error
|
setup_error
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
main
|
main $*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user