TawfikDaim / home_automation

home automation user stories
0 stars 0 forks source link

Initial HA/motion-eye installation on VM #40

Open TawfikDaim opened 4 months ago

TawfikDaim commented 4 months ago

1.install ubuntu 20.04 on bare metal acting as host

  1. Oracle Virtualbox to host VMs Linux ubuntu:
    install oracle virtualbox 6, make virtualbox auto start 
         a. `which virtualbox`-> /usr/bin/virtualbox -> add that to auto start in ubuntu

2.1. homeassistant (including mosquito as add-on) 2.2 Z2MQTT (connecting to homeassistant on IP and loging using user name and password defined in mosquitto add-on) 2.3 motioneye (maybe multiple of needed)

Home-assistant 1- install Linux 20.4 (not 22.4) on a vm dedicated to homeassistant

Z2MQTT steps and config file instructions: https://www.zigbee2mqtt.io/guide/installation/01_linux.html#starting-zigbee2mqtt

frontend: port: 8080 homeassistant: false permit_join: false mqtt: base_topic: zigbee2mqtt server: mqtt://192.168.1.16:1883 user: homeassistant password: Newipad1 keepalive: 60 reject_unauthorized: true version: 4 serial: port: /dev/ttyACM0 adapter: ezsp advanced: pan_id: 47127 network_key:

3- install MotionEye dockers on a new VM dedicated to motioneye 1) sudo apt install docker.io 2) sudo docker run --name="motioneye" -p 8765:8765 --hostname="motioneye" -v /etc/localtime:/etc/localtime:ro -v /etc/motioneye:/etc/motioneye -v /var/lib/motioneye:/var/lib/motioneye --restart="always" --detach=true ccrisan/motioneye:master-amd64 3- install sudo apt install net-tools (to get the IP address using ifocnfig) 4- access docker e.g. http://192.168.1.125:8765/ 5- rtsp://admin:Newipad1@192.168.1.101:554/Streaming/Channel/101

make VM auto start on boot

  • on terminal type: groups

$ groups gt2 adm dialout cdrom floppy sudo audio dip video plugdev netdev wireshark bluetooth scanner kaboxer vboxusers

If not, let’s add ourselves:

$ sudo usermod -a -G vboxusers $USER

Next, let’s now create the systemd template file:

$ sudo vi /etc/systemd/system/autostart_vm@.service

Let’s add some basic configurations:

[Unit] Description= Guest VM %I After=network.target vboxdrv.service Before=runlevel2.target shutdown.target

[Service] User=host_username Group=vboxusers Type=forking TimeoutSec=5min IgnoreSIGPIPE=no KillMode=process GuessMainPID=no RemainAfterExit=yes ExecStart=/usr/bin/VBoxManage startvm %i --type headless ExecStop=/usr/bin/VBoxManage controlvm %i acpipowerbutton

[Install] WantedBy=multi-user.target

Once we’ve added these configurations, let’s save the file.

We now need to enable the unit file for our guest VM. But first, we’ll need to choose the VM we want to autostart. Let’s list the VMs on our system:

$ VBoxManage list vms "Ubuntu" {c56a9b95-3f3e-48c6-951e-3c03ad699ca9} "kali2" {5b261408-8d2f-44536-a643-d2fa68394d8e} "userkali" {59f9cb1f-c439-409c-ad7e-tb7dc1d3h554}

For this example, we’ll use ‘userkali’.

Let’s enable the ‘userkali’ VM to run on startup. This will create a symlink:

$ sudo systemctl enable autostart_vm@userkali Created symlink /etc/systemd/system/multi-user.target.wants/autostart_vm@userkali.service → /etc/systemd/system/autostart_vm@.service.

Now, let’s check the status of our unit:

$ sudo systemctl status autostart_vm@userkali ○ autostart_vm@userkali.service - Guest VM userkali Loaded: loaded (/etc/systemd/system/autostart_vm@.service; enabled; preset> Active: inactive (dead)

To ensure that our configuration file is working right, let’s run the following commands:

$ sudo systemctl daemon-reload $ sudo systemctl start autostart_vm@userkali $ sudo systemctl status autostart_vm@userkali

We use the systemctl to manage systemd units. After making any changes in the unit file, we must reload the systemd manager configurations using the daemon-reload command.

Next, we use the start option to activate our unit file (autostart_vm@userkali). Lastly, we use the status option to check the current runtime state (including logs) of our unit file.

If we check the status, it should be active:

================================================================================end