[How-To] Home Assistant in a jail (tested on 9.10)

Status
Not open for further replies.

mrMuppet

Contributor
Joined
Mar 14, 2014
Messages
192
Hier is a small tutorial how to install Home Assistant on your FreeNAS machine.

create a jail
in the jail enter:
Code:
pkg update
pkg upgrade
pkg install python35
pkg install py35-sqlite3
python3.5 -m ensurepip


after that you have to install HomeAssistant
Code:
pip3 install homeassistant

and start it
Code:
 hass --open-ui


Autostart
You may recognize that hass ist closed everytime you close your putty-session. I don't have an autostart to offer at the moment, but If you don't mind running it manually, you can install tmux in your jail and run it with that. It'll stay running even if you disconnect from PuTTY.

Install:
Code:
pkg install tmux


Run it:
Code:
tmux
hass --open-ui


Few extra things you may want to know about tmux:
to detach your tmux session: CTRL-B then d
To reattach to a running tmux session:
Code:
tmux att


Update Home Assitant with
Code:
pip3 install --upgrade homeassistant
 

camrun

Cadet
Joined
Aug 31, 2015
Messages
3
Another option to keep it running is to use the screen command to open a new "screen" in the terminal then start HASS then you and press Ctrl+A+D and that will disconnect the screen without exiting the session. This leaves Whatever is running in that screen running in the background even when you close our main session.
 

mattyman

Dabbler
Joined
Dec 22, 2013
Messages
13
A much more elegant solution is to get it to run when the jail is started.
Create a new file in the /etc directory and name it rc.local
Add the following line to it and save it.
Code:
/usr/local/bin/hass --open-ui

Once that is done you'll need to make the file we just created, executable by using chmod.
Code:
chmod 755 /etc/rc.local

Restart the jail and homeassistant should start up automatically.
 

tprelog

Patron
Joined
Mar 2, 2016
Messages
291
Thanks for the guide. I followed this on FreeNAS 11 and worked great. I have been working on a proper startup based on mattyman's solution above. Here's what I have so far... It works but I'm not sure if I'm following all best practices and preferred ways of doing things. I have several working solutions up till this point but I feel this is most complete even if not perfect... Also please note Im running Home Assistant in a virtualenv as non-root user "homeassistant". While this will work to start home assistant installed following the OP guide, slight modification would be required. (*)

Inside your HA jail...
Create a new file:
/usr/local/etc/rc.d/homeassistant

Add the following and save:
#!/bin/sh
#
# PROVIDE: homeassistant
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# FreeNAS 11 Jail -- Python VirtualEnv -- Home Assistant Daemon -- Non-Root User
#
# The following are available to configure this service:
# Change these options in /etc/rc.conf.local or /etc/rc.conf
# EXAMPLE: sysrc homeassistant_enable=yes
# EXAMPLE: sysrc homeassistant_data_dir=/home/homeassistant/.homeassistant
#
# homeassistant_enable: Set to YES to enable the homeassistant service.
# Default: NO
# homeassistant_user: The user account used to run the homeassistant daemon.
# > This is optional, however do not specifically set this to an
# > empty string as this will cause the daemon to run as root.
# Default: homeassistant
# homeassistant_group: The group account used to run the homeassistant daemon.
# > This is optional, however do not specifically set this to an
# > empty string as this will cause the daemon to run with group wheel.
# Default: homeassistant
# homeassistant_data_dir: Directory where homeassistant configuration files will stored.
# Default: /usr/home/homeassistant/.homeassistant


. /etc/rc.subr
name=homeassistant
rcvar=${name}_enable
load_rc_config ${name}

: ${homeassistant_enable:="NO"}
: ${homeassistant_user:="homeassistant"}
: ${homeassistant_group:="homeassistant"}
: ${homeassistant_data_dir:="/usr/home/${homeassistant_user}/.homeassistant"}

pid_dir="/srv/homeassistant/var/run"
pidfile="${pid_dir}/homeassistant.pid"


command="/srv/homeassistant/bin/hass"
command_args="-c ${homeassistant_data_dir} --pid-file ${pidfile} --daemon"

start_precmd=homeassistant_precmd
homeassistant_precmd()
{
if [ ! -d "${pid_dir}" ]; then
install -d -g ${homeassistant_group} -o ${homeassistant_user} -- "${pid_dir}";
fi

if [ ! -d "${homeassistant_data_dir}" ]; then
install -d -g ${homeassistant_group} -o ${homeassistant_user} -m 775 -- "${homeassistant_data_dir}";
fi
}

stop_cmd=":"

stop_postcmd=homeassistant_postcmd
homeassistant_postcmd()
{
rm -f -- "${pidfile}"
}

run_rc_command "$1"


Make the file executable:
# chmod +x /usr/local/etc/rc.d/homeassistant

Enable the service to auto start:
# sysrc homeassistant_enable=yes

And finally if not yet running you can start Home Assistant:
# service homeassistant start

I can start a new post with a modified guide containing the extra steps to run home assistant inside the virtualenv if anybody is interested.

(*) Changes to work with OP guide can be easily made:
Edit portion of file above to match:

: ${homeassistant_enable:="NO"}
#: ${homeassistant_user:="homeassistant"}
#: ${homeassistant_group:="homeassistant"}
#: ${homeassistant_data_dir:="/usr/home/${homeassistant_user}/.homeassistant"}

pid_dir="/var/run"
pidfile="${pid_dir}/homeassistant.pid"

command="/usr/local/bin/hass"
command_args="-c ${homeassistant_data_dir} --pid-file ${pidfile} --daemon"


Set path to configuration:
# sysrc homeassistant_data_dir=$YOUR_PATH_TO CONFIG
 
Last edited:

wmn79

Explorer
Joined
Apr 23, 2015
Messages
59
I can start a new post with a modified guide containing the extra steps to run home assistant inside the virtualenv if anybody is interested.

Not sure why you would want to run homeassistant in a virtual environment? In my opinion a jail is already a virtual environment so installing in a virtual environment in a jail seems like your doing things double. I might be wrong but would like to understand the advantages of installing in a virtual environment. I did have HA installed in a virtual environment on my PI.

Having it currently installed in a FreeNas 11 jail currently without issues.

My rc.local currently looks like this:
Code:
/usr/local/bin/hass --open-ui --config /root/.homeassistant/ &

The config path looks like this because I didn't create a user for it when I installed HomeAssistant. Not sure if it is a real issue but I always learned not to use the root user for these kind of operations. So I will be looking into changing that in the future.
 
Joined
May 2, 2017
Messages
211
Care to help a brother out? LOL

I'm about to try out Home Assistant myself, but ran into some issues on the test jail. I've started out here now with a blank jail on FreeNAS 11.1 and want to do this the right way. When following other tutorials, the Home Assistant setup ran into issues. I followed the "official" tutorial which was tested on 9.10, but setup choked. The tutorial I used was here...

https://home-assistant.io/docs/installation/freenas/

Setup gave lots of vague notices about not finding components on this step...

Code:
/usr/local/bin/hass --open-ui --config /home/.homeassistant/ &


After setup failed, the "History" and "Logbook" functions showed as not working in the interface of Home Assistant, so there was something screwed up there. But if you could list the specific commands needed to set this up inside an 11.1 jail to help me get started, I'd appreciate it very much. I'm up and ready to start from scratch with a freshly installed jail at the moment...

And of course, there is no rc.local file anymore in FreeBSD, so I need to work around the proper way to autostart.

Thanks in advance!
Steven


Thanks for the guide. I followed this on FreeNAS 11 and worked great. I have been working on a proper startup based on mattyman's solution above. Here's what I have so far... It works but I'm not sure if I'm following all best practices and preferred ways of doing things. I have several working solutions up till this point but I feel this is most complete even if not perfect... Also please note Im running Home Assistant in a virtualenv as non-root user "homeassistant". While this will work to start home assistant installed following the OP guide, slight modification would be required. (*)

Inside your HA jail...
Create a new file:
/usr/local/etc/rc.d/homeassistant

Add the following and save:
#!/bin/sh
#
# PROVIDE: homeassistant
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# FreeNAS 11 Jail -- Python VirtualEnv -- Home Assistant Daemon -- Non-Root User
#
# The following are available to configure this service:
# Change these options in /etc/rc.conf.local or /etc/rc.conf
# EXAMPLE: sysrc homeassistant_enable=yes
# EXAMPLE: sysrc homeassistant_data_dir=/home/homeassistant/.homeassistant
#
# homeassistant_enable: Set to YES to enable the homeassistant service.
# Default: NO
# homeassistant_user: The user account used to run the homeassistant daemon.
# > This is optional, however do not specifically set this to an
# > empty string as this will cause the daemon to run as root.
# Default: homeassistant
# homeassistant_group: The group account used to run the homeassistant daemon.
# > This is optional, however do not specifically set this to an
# > empty string as this will cause the daemon to run with group wheel.
# Default: homeassistant
# homeassistant_data_dir: Directory where homeassistant configuration files will stored.
# Default: /usr/home/homeassistant/.homeassistant


. /etc/rc.subr
name=homeassistant
rcvar=${name}_enable
load_rc_config ${name}

: ${homeassistant_enable:="NO"}
: ${homeassistant_user:="homeassistant"}
: ${homeassistant_group:="homeassistant"}
: ${homeassistant_data_dir:="/usr/home/${homeassistant_user}/.homeassistant"}

pid_dir="/srv/homeassistant/var/run"
pidfile="${pid_dir}/homeassistant.pid"


command="/srv/homeassistant/bin/hass"
command_args="-c ${homeassistant_data_dir} --pid-file ${pidfile} --daemon"

start_precmd=homeassistant_precmd
homeassistant_precmd()
{
if [ ! -d "${pid_dir}" ]; then
install -d -g ${homeassistant_group} -o ${homeassistant_user} -- "${pid_dir}";
fi

if [ ! -d "${homeassistant_data_dir}" ]; then
install -d -g ${homeassistant_group} -o ${homeassistant_user} -m 775 -- "${homeassistant_data_dir}";
fi
}

stop_cmd=":"

stop_postcmd=homeassistant_postcmd
homeassistant_postcmd()
{
rm -f -- "${pidfile}"
}

run_rc_command "$1"


Make the file executable:
# chmod +x /usr/local/etc/rc.d/homeassistant

Enable the service to auto start:
# sysrc homeassistant_enable=yes

And finally if not yet running you can start Home Assistant:
# service homeassistant start

I can start a new post with a modified guide containing the extra steps to run home assistant inside the virtualenv if anybody is interested.

(*) Changes to work with OP guide can be easily made:
Edit portion of file above to match:

: ${homeassistant_enable:="NO"}
#: ${homeassistant_user:="homeassistant"}
#: ${homeassistant_group:="homeassistant"}
#: ${homeassistant_data_dir:="/usr/home/${homeassistant_user}/.homeassistant"}

pid_dir="/var/run"
pidfile="${pid_dir}/homeassistant.pid"

command="/usr/local/bin/hass"
command_args="-c ${homeassistant_data_dir} --pid-file ${pidfile} --daemon"


Set path to configuration:
# sysrc homeassistant_data_dir=$YOUR_PATH_TO CONFIG
 

wmn79

Explorer
Joined
Apr 23, 2015
Messages
59
Care to help a brother out? LOL

I'm about to try out Home Assistant myself, but ran into some issues on the test jail. I've started out here now with a blank jail on FreeNAS 11.1 and want to do this the right way. When following other tutorials, the Home Assistant setup ran into issues. I followed the "official" tutorial which was tested on 9.10, but setup choked. The tutorial I used was here...

https://home-assistant.io/docs/installation/freenas/

Setup gave lots of vague notices about not finding components on this step...

Code:
/usr/local/bin/hass --open-ui --config /home/.homeassistant/ &


After setup failed, the "History" and "Logbook" functions showed as not working in the interface of Home Assistant, so there was something screwed up there. But if you could list the specific commands needed to set this up inside an 11.1 jail to help me get started, I'd appreciate it very much. I'm up and ready to start from scratch with a freshly installed jail at the moment...

And of course, there is no rc.local file any more in FreeBSD, so I need to work around the proper way to autostart.

Thanks in advance!
Steven
The issue with the history and logbook is probably due to SQlite3, had that issue as well after updating a while ago. I fixed it with the instructions from this link: https://community.home-assistant.io/t/hass-on-freenas-11-1-undefined-symbol-fdatasync/36001/3 so instead of using the SQLite package you have to manually compile the software.
 
Joined
May 2, 2017
Messages
211
The issue with the history and logbook is probably due to SQlite3, had that issue as well after updating a while ago. I fixed it with the instructions from this link: https://community.home-assistant.io/t/hass-on-freenas-11-1-undefined-symbol-fdatasync/36001/3 so instead of using the SQLite package you have to manually compile the software.

So can you put this part into newbie english? LOL

ssh into that jail.
portsnap fetch
portsnap extract
whereis sqlite3
(cd into that directory)
make deinstall
make install clean ALLOW_UNSUPPORTED_SYSTEM=true

Not sure what you mean by manually compiling the software...

Thanks! Looks like my exact issue.
 
Joined
May 2, 2017
Messages
211
The issue with the history and logbook is probably due to SQlite3, had that issue as well after updating a while ago. I fixed it with the instructions from this link: https://community.home-assistant.io/t/hass-on-freenas-11-1-undefined-symbol-fdatasync/36001/3 so instead of using the SQLite package you have to manually compile the software.

So I have a fresh jail... I'm updating the base OS, and haven't done the install of SQLITE yet, what commands should I run to install the appropriate DB? is the issue...? I'm working through these commands...

Code:
pkg update
pkg upgrade
pkg install python35
pkg install py35-sqlite3
python3.5 -m ensurepip


Thanks!
 

wmn79

Explorer
Joined
Apr 23, 2015
Messages
59
Ok if you start with a new jail I would go with Python 3.6 instead of 3.5 do the following:

pkg update
pkg upgrade
pkg install python36
portsnap fetch
portsnap extract
cd /usr/ports/databases/py36-sqlite3
make install clean ALLOW_UNSUPPORTED_SYSTEM=true
python3.6 -m ensurepip

pip3 install homeassistant

Check if it works:
hass --open-ui

If it works do the following to have it autostarted (thanks to mattyman for these instructions):
Create a new file in the /etc directory and name it rc.local
Add the following line to it and save it:

/usr/local/bin/hass --open-ui

Once that is done you'll need to make the file we just created, executable by using chmod.
Code:
chmod 755 /etc/rc.local

Restart the jail and homeassistant should start up automatically.

You should be all set after that.
 
Joined
May 2, 2017
Messages
211
Ok if you start with a new jail I would go with Python 3.6 instead of 3.5 do the following:

pkg update
pkg upgrade
pkg install python36
portsnap fetch
portsnap extract
cd /usr/ports/databases/py36-sqlite3
make install clean ALLOW_UNSUPPORTED_SYSTEM=true
python3.6 -m ensurepip

pip3 install homeassistant

Check if it works:
hass --open-ui

If it works do the following to have it autostarted (thanks to mattyman for these instructions):
Create a new file in the /etc directory and name it rc.local
Add the following line to it and save it:

/usr/local/bin/hass --open-ui

Once that is done you'll need to make the file we just created, executable by using chmod.
Code:
chmod 755 /etc/rc.local

Restart the jail and homeassistant should start up automatically.

You should be all set after that.

Getting the same... Startup stalls right here...

Code:
INFO:homeassistant.core:Bus:Handling <Event call_service[L]: domain=persistent_n
otification, service=create, service_data=title=Invalid config, message=The foll
owing components and platforms could not be set up:							 
																			   
 - [frontend](https://home-assistant.io/components/frontend/)				   
																			   
Please check your config., notification_id=invalid_config, service_call_id=34507
644880-2>																	   
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: entity_id=persiste
nt_notification.invalid_config, old_state=None, new_state=<state persistent_noti
fication.invalid_config=notifying; title=Invalid config, message=The following c
omponents and platforms could not be set up:									
																			   
 - [frontend](https://home-assistant.io/components/frontend/)				   
																			   
Please check your config. @ 2018-03-23T18:05:44.935591-04:00>>				 
INFO:homeassistant.core:Bus:Handling <Event service_executed[L]: service_call_id
=34507644880-2>																 
WARNING:homeassistant.setup:Setup of recorder is taking over 10 seconds.		
INFO:homeassistant.core:Bus:Handling <Event system_log_event[L]: timestamp=15218
42750.089063, level=WARNING, message=Setup of recorder is taking over 10 seconds
., exception=, source=bootstrap.py>		 
 

tprelog

Patron
Joined
Mar 2, 2016
Messages
291
I just reinstalled homeassistant into a new jail myself and I now have everything working... A few thing I think worth mentioning.

I did this on FreNAS 11.1U2

I was looking into this "make install clean ALLOW_UNSUPPORTED_SYSTEM=true" option that is required to build py-36-sqlite3. From what I gather in my NON EXPERT OPINION bottom line is:
Creating a jail using GUI you get a jail based on 11.0-RELEASE-p1 which is no longer supported.
Creating a jail using the new iocage system I get a jail based on 11.1-RELEASE-p8

I suspect the base jail freenas creates has not been updates because of the this...
Per FreeNAS Manual -- "The jails infrastructure is transitioning from the old warden backend to the new iocage backend. This transition process requires the middleware API calls to be rewritten for the new UI. It is expected that the transition will be complete with FreeNAS® version 11.2. Since jails created in the old UI use the warden backend, jails created in the new UI use the iocage backend, and both use different API versions, they are not compatible. While a migration script will be made available when the transition is complete, it will not be able to anticipate every configuration scenario for every application installed in jails. At that time, the recommendation will be to: create new jails using the new UI, copy over any existing configurations, and delete the old jail datasets once the new jails are working as expected."

I should mention here that I created and managed my iocage jail from the command line. I did NOT try this using the new GUI.

That said, Using the FreeNAS Manual and IOCOAGE Documentation I was able to switch my homeassistant jail (and all others) over to the new iocage jail system. After switching to the new iocage jail I no longer need to manually compile any software and the basics from the old guides will work again.

I'm not an expert and even further from a freenas expert but I did take some notes and made myself a basic quick step guide on everything from setting up iocage thru auto starting homeassistant using a freebsd startup script (recommended freebsd way?)
Its an updated and less words version of this. As I simply followed other peoples great guides putting this together I never intended to share it but Id be willing too if you'd like to give it a try... It's 99% other peoples work and 1% just put together specifically for creating a jail with homeassistant by me.
 
Last edited:

tprelog

Patron
Joined
Mar 2, 2016
Messages
291
Getting the same... Startup stalls right here...

Code:
INFO:homeassistant.core:Bus:Handling <Event call_service[L]: domain=persistent_n
otification, service=create, service_data=title=Invalid config, message=The foll
owing components and platforms could not be set up:							
																			 
 - [frontend](https://home-assistant.io/components/frontend/)				 
																			 
Please check your config., notification_id=invalid_config, service_call_id=34507
644880-2>																	 
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: entity_id=persiste
nt_notification.invalid_config, old_state=None, new_state=<state persistent_noti
fication.invalid_config=notifying; title=Invalid config, message=The following c
omponents and platforms could not be set up:									
																			 
 - [frontend](https://home-assistant.io/components/frontend/)				 
																			 
Please check your config. @ 2018-03-23T18:05:44.935591-04:00>>				
INFO:homeassistant.core:Bus:Handling <Event service_executed[L]: service_call_id
=34507644880-2>																
WARNING:homeassistant.setup:Setup of recorder is taking over 10 seconds.		
INFO:homeassistant.core:Bus:Handling <Event system_log_event[L]: timestamp=15218
42750.089063, level=WARNING, message=Setup of recorder is taking over 10 seconds
., exception=, source=bootstrap.py>		


I had this problem myself. In my case it was my old config files. I deleted everything in /home/.homeassistant/ and then it started fine. I then went back and slowly restored my old config until I found/fixed my config file problems
 
Joined
May 2, 2017
Messages
211
I had this problem myself. In my case it was my old config files. I deleted everything in /home/.homeassistant/ and then it started fine. I then went back and slowly restored my old config until I found/fixed my config file problems

This is a new installation...
 
Joined
May 2, 2017
Messages
211
I just reinstalled homeassistant into a new jail myself and I now have everything working... A few thing I think worth mentioning.

I did this on FreNAS 11.1U2

I was looking into this "make install clean ALLOW_UNSUPPORTED_SYSTEM=true" option that is required to build py-36-sqlite3. From what I gather in my NON EXPERT OPINION bottom line is:
Creating a jail using GUI you get a jail based on 11.0-RELEASE-p1 which is no longer supported.
Creating a jail using the new iocage system I get a jail based on 11.1-RELEASE-p8

I suspect the base jail freenas creates has not been updates because of the this...
Per FreeNAS Manual -- "The jails infrastructure is transitioning from the old warden backend to the new iocage backend. This transition process requires the middleware API calls to be rewritten for the new UI. It is expected that the transition will be complete with FreeNAS® version 11.2. Since jails created in the old UI use the warden backend, jails created in the new UI use the iocage backend, and both use different API versions, they are not compatible. While a migration script will be made available when the transition is complete, it will not be able to anticipate every configuration scenario for every application installed in jails. At that time, the recommendation will be to: create new jails using the new UI, copy over any existing configurations, and delete the old jail datasets once the new jails are working as expected."

I should mention here that I created and managed my iocage jail from the command line. I did NOT try this using the new GUI.

That said, Using the FreeNAS Manual and IOCOAGE Documentation I was able to switch my homeassistant jail (and all others) over to the new iocage jail system. After switching to the new iocage jail I no longer need to manually compile any software and the basics from the old guides will work again.

I'm not an expert and even further from a freenas expert but I did take some notes and made myself a basic quick step guide on everything from setting up iocage thru auto starting homeassistant using a freebsd startup script (recommended freebsd way?)
Its an updated and less words version of this. As I simply followed other peoples great guides putting this together I never intended to share it but Id be willing too if you'd like to give it a try... It's 99% other peoples work and 1% just put together specifically for creating a jail with homeassistant by me.

Could be an issue... I'll have to look deeper into that.
 

wmn79

Explorer
Joined
Apr 23, 2015
Messages
59
I just reinstalled homeassistant into a new jail myself and I now have everything working... A few thing I think worth mentioning.

I did this on FreNAS 11.1U2

I was looking into this "make install clean ALLOW_UNSUPPORTED_SYSTEM=true" option that is required to build py-36-sqlite3. From what I gather in my NON EXPERT OPINION bottom line is:
Creating a jail using GUI you get a jail based on 11.0-RELEASE-p1 which is no longer supported.
Creating a jail using the new iocage system I get a jail based on 11.1-RELEASE-p8

I suspect the base jail freenas creates has not been updates because of the this...
Per FreeNAS Manual -- "The jails infrastructure is transitioning from the old warden backend to the new iocage backend. This transition process requires the middleware API calls to be rewritten for the new UI. It is expected that the transition will be complete with FreeNAS® version 11.2. Since jails created in the old UI use the warden backend, jails created in the new UI use the iocage backend, and both use different API versions, they are not compatible. While a migration script will be made available when the transition is complete, it will not be able to anticipate every configuration scenario for every application installed in jails. At that time, the recommendation will be to: create new jails using the new UI, copy over any existing configurations, and delete the old jail datasets once the new jails are working as expected."

I should mention here that I created and managed my iocage jail from the command line. I did NOT try this using the new GUI.

That said, Using the FreeNAS Manual and IOCOAGE Documentation I was able to switch my homeassistant jail (and all others) over to the new iocage jail system. After switching to the new iocage jail I no longer need to manually compile any software and the basics from the old guides will work again.

I'm not an expert and even further from a freenas expert but I did take some notes and made myself a basic quick step guide on everything from setting up iocage thru auto starting homeassistant using a freebsd startup script (recommended freebsd way?)
Its an updated and less words version of this. As I simply followed other peoples great guides putting this together I never intended to share it but Id be willing too if you'd like to give it a try... It's 99% other peoples work and 1% just put together specifically for creating a jail with homeassistant by me.
Always useful for others to share what you did to make it working. I'm still working with an old jail version for which I used the "ALLOW UNSUPPORTED SYSTEM=true" solution to keep it running. Need to make the switch to the new IOCAGE jails some time as well so all help is appreciated.
 

tprelog

Patron
Joined
Mar 2, 2016
Messages
291
Ok give me a few... I'll post a short and sweet guide tonight

Always useful for others to share what you did to make it working. I'm still working with an old jail version for which I used the "ALLOW UNSUPPORTED SYSTEM=true" solution to keep it running. Need to make the switch to the new IOCAGE jails some time as well so all help is appreciated.
 

tprelog

Patron
Joined
Mar 2, 2016
Messages
291
Alright down and dirty... As it says under my user name "Newbie" Although I have done my homework (as much as time allows) I am not an expert. I have tested worked this out and tested using a VM and I recommend you do the same before you just copy and paste these command onto your running system. Better safe then sorry! That said I have followed these steps on my FreeNAS version 11.2U2-U3 at the time of this writing and have successfully switched all my jails over the the new iocage back end.

Need to pick a zpool for iocage. I just used the same zpool I already have setup in the GUI for the warden backend. In my case it's called "jail" I used the GUI to create a dataset called "iocage" in my "jail" zpool. The name of your zpool may most likely be different. After you've chosen your zpool and created the "iocage"dataset its time to jump over to the command line of your freenas and activate iocage. This is only for the very time you use iocage. If you've tried making a jail from the new GUI this has most likely already been done for you.
Code:
iocage activate jail

list releases of freebsd. you'll be choosing number 6
Code:
iocage fetch

create our jail. I called mine "homeassistant" and since I assign IP address from my router I create jail to use dhcp
Code:
iocage create -r 11.1-RELEASE -n homeassistant dhcp=on bpf=yes vnet=on boot=on

next to get in the jail console
Code:
iocage console homeassistant

I switch my jail to get latest updates instead of quarterly as set by default. While I personally prefer to have the latest updates I believe this step is optional.
Code:
mkdir -p /usr/local/etc/pkg/repos
ee /usr/local/etc/pkg/repos/FreeBSD.conf

copy and paste. press escape to save and exit
Code:
FreeBSD: {
url: "pkg+http://pkg.FreeBSD.org/${ABI}/latest"
 }

Code:
pkg update
pkg upgrade
pkg install python36 py36-sqlite3 bash gmake ca_root_nss

*Just a note here I needed gmake and ca_root_nss for the zwave component to build properly. The requirement for ca_root_nss is new after freenas 11.1 U2. It resolved an issue were ssl certs were failing to verify. I had the same issue with gmusicproxy I have running in a separate jail but that's a different post.

From this point on I believe you can finish install homeassistant following you desired method.
My preference is to create a user "hass" and install homeassistant inside a python virtualenv. My virtualenv lives in a directory I created "/srv/homeassistant". The rest of this quick guide will do the same. I should mention it has been pointed out to me that a virtualenv inside a jail is not need since the jail itself is already well... a jail! I still prefer my current method.

The next commands create a home dir and user hass. I add "hass" to the "dialer" group as required by my z-wave stick. I also assign my hass user a UID and GUID of 990. This is completely optional and just a choice I make for myself. Further explanation to this choice is beyond the scope of this quick guide.
Code:
install -d -g hass -o hass -m 775 -- /home/hass
pw addgroup -g 990 -n hass
pw adduser -u 990 -n hass -d /home/hass -s /usr/local/bin/bash -G dialer -c "Daemon user for Homeassistant"


install and create dir for virtualenv
Code:
python3.6 -m ensurepip
pip3 install --upgrade pip
pip3 install --upgrade virtualenv
install -d -g hass -o hass -m 775 -- /srv/homeassistant


change over to our user hass and finally install homeassistant!
Code:
su hass
virtualenv -p /usr/local/bin/python3.6 /srv/homeassistant
source /srv/homeassistant/bin/activate
pip3 install --upgrade homeassistant
deactivate


ready to test! be sure your still user "hass" if you typed exit or used 'Ctrl+D' to exit the virtualenv you may have been switched back to user "root"
you should be able to start homeassistant with this to test it out
Code:
/srv/homeassistant/bin/hass 


I'll post a follow up with my auto start

Made a few edits to correct mostly spelling. Also added bash to pkg install for the virtualenv to work
 
Last edited:

tprelog

Patron
Joined
Mar 2, 2016
Messages
291
While its quick and simple (and definitely works!) to just add one line to rc.local to get homeassistant up and running I wanted to make a more official way to start home assistant. I model most of choices mainly by how the Emby plug-in is setup. As such this script started by copying and editing the Emby startup script to reflect homeassistant. This is my latest version which is different than what I've posted above. This should also work if you followed the guide above. As always you may need to edit some options but there are some cool ways to that since this is a "real" start up script.
first lets make file.
Code:
iocage console homeassistant

Code:
mkdir -p /usr/local/etc/rc.d
ee /usr/local/etc/rc.d/homeassistant

copy and paste the escape to save and exit
Code:
#!/bin/sh

# PROVIDE: hass-server
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
#
# Add the following lines to /usr/local/etc/rc.d/homeassistant
#
# homeassistant_enable:	Set to YES to enable the homeassistant service.
#			Default: NO
# homeassistant_user:	The user account used to run the homeassistant daemon.
#			This is optional, however do not specifically set this to an
#			empty string as this will cause the daemon to run as root.
#			Default: USER_NAME
# homeassistant_group:	The group account used to run the homeassistant daemon.
#			This is optional, however do not specifically set this to an
#			empty string as this will cause the daemon to run with group wheel.
#			Default: USER_GROUP
# homeassistant_dir:	Directory where --- is located.
#			Default: USER_HOME

# sysrc homeassistant_enable=yes

. /etc/rc.subr
name=homeassistant
rcvar=${name}_enable

pidfile_child="/var/run/${name}.pid"
pidfile="/var/run/${name}_daemon.pid"

load_rc_config ${name}
: ${homeassistant_enable:="NO"}
: ${homeassistant_user:="hass"}
: ${homeassistant_group:="hass"}
: ${homeassistant_config_dir:="/home/hass/homeassistant"}

command="/usr/sbin/daemon"

start_precmd=${name}_precmd
homeassistant_precmd()
{
		rc_flags="-f -P ${pidfile} -p ${pidfile_child} /srv/homeassistant/bin/hass --config ${homeassistant_config_dir} ${rc_flags}"
		
	if [ ! -e "${pidfile_child}" ]; then
			install -g ${homeassistant_group} -o ${homeassistant_user} -- /dev/null "${pidfile_child}";
	fi

	if [ ! -e "${pidfile}" ]; then
			install -g ${homeassistant_group} -o ${homeassistant_user} -- /dev/null "${pidfile}";
	fi
	
	if [ ! -d "${homeassistant_config_dir}" ]; then
		install -d -g ${homeassistant_group} -o ${homeassistant_user} -- "${homeassistant_config_dir}";
	fi
}

stop_postcmd=${name}_postcmd
homeassistant_postcmd()
{
	rm -f -- "${pidfile}"
	rm -f -- "${pidfile_child}"
}

run_rc_command "$1"


make executable - enable service - start homeassistant
Code:
chmod +x /usr/local/etc/rc.d/homeassistant
sysrc homeassistant_enable=yes
service homeassistant start



A few more things about using the script above
--------------------------------------------
options for homeassistant service
Code:
service homeassistant [ start | restart | status | stop ] 

These options can be changed from the command line
Code:
: ${homeassistant_enable:="NO"}
: ${homeassistant_user:="hass"}
: ${homeassistant_group:="hass"}
: ${homeassistant_config_dir:="/home/hass/homeassistant"}

for example we have already changed the : ${homeassistant_enable:="NO"} to : ${homeassistant_enable:="YES"}
Code:
sysrc homeassistant_enable=yes


change user or group
Code:
sysrc homeassistant_user=your_new_user
sysrc homeassistant_group=your_new_group

change config location
Code:
sysrc homeassistant_config_dir=your_new_config


If you need to change the location of the homeassistant exe you have to edit the script file by hand. locate and change "/srv/homeassistant/bin/hass" in the following line in the script above
Code:
rc_flags="-f -P ${pidfile} -p ${pidfile_child} /srv/homeassistant/bin/hass --config ${homeassistant_config_dir} ${rc_flags}"
 

wmn79

Explorer
Joined
Apr 23, 2015
Messages
59
Thanks for your guides @tprelog I managed to install homeassistant in a new jail and created the service successfully. After that I have installed appdaemon in the virtualenv as well and created a service for that as well by editing the text you had provided for the homeassistant service.

So if anyone wants to use that service as well see below and follow the instructions like there were for the homeassistant service:

Code:
#!/bin/sh

#
# Add the following lines to /usr/local/etc/rc.d/appdaemon
#
# appdaemon_enable:	Set to YES to enable the appdaemon service.
#			Default: NO
# appdaemon_user:	The user account used to run the appdaemon daemon.
#			This is optional, however do not specifically set this to an
#			empty string as this will cause the daemon to run as root.
#			Default: USER_NAME
# appdaemon_group:	The group account used to run the appdaemon daemon.
#			This is optional, however do not specifically set this to an
#			empty string as this will cause the daemon to run with group wheel.
#			Default: USER_GROUP
# appdaemon_dir:	Directory where --- is located.
#			Default: USER_HOME

# sysrc appdaemon_enable=yes

. /etc/rc.subr
name=appdaemon
rcvar=${name}_enable

pidfile_child="/var/run/${name}.pid"
pidfile="/var/run/${name}_daemon.pid"

load_rc_config ${name}
: ${appdaemon_enable:="NO"}
: ${appdaemon_user:="hass"}
: ${appdaemon_group:="hass"}
: ${appdaemon_config_dir:="/home/hass/appdaemon"}

command="/usr/sbin/daemon"

start_precmd=${name}_precmd
appdaemon_precmd()
{
		rc_flags="-f -P ${pidfile} -p ${pidfile_child} /srv/homeassistant/bin/appdaemon -c ${appdaemon_config_dir} ${rc_flags}"
	 
	if [ ! -e "${pidfile_child}" ]; then
			install -g ${appdaemon_group} -o ${appdaemon_user} -- /dev/null "${pidfile_child}";
	fi

	if [ ! -e "${pidfile}" ]; then
			install -g ${appdaemon_group} -o ${appdaemon_user} -- /dev/null "${pidfile}";
	fi
 
	if [ ! -d "${appdaemon_config_dir}" ]; then
		install -d -g ${appdaemon_group} -o ${appdaemon_user} -- "${appdaemon_config_dir}";
	fi
}

stop_postcmd=${name}_postcmd
appdaemon_postcmd()
{
	rm -f -- "${pidfile}"
	rm -f -- "${pidfile_child}"
}

run_rc_command "$1"
 
Status
Not open for further replies.
Top