Site updated at 2016-05-13 21:09:20 UTC
This commit is contained in:
parent
ebea4ecf27
commit
26e61e4377
20 changed files with 58 additions and 65 deletions
|
@ -89,17 +89,17 @@
|
|||
<hr class="divider">
|
||||
|
||||
|
||||
<p>There are several reasons why it makes sense to run Home Assistant in a virtual environment. A virtualenv encapsulates all aspect of a Python environment within a single directory tree. That means the Python packages you install for Home Assistant won’t interact with the rest of your system and vice-versa. It means a random upgrade for some other program on your computer won’t break Home Assitant, and it means you don’t need to install Python packages as root.</p>
|
||||
<p>There are several reasons why it makes sense to run Home Assistant in a virtual environment. A <a href="https://virtualenv.pypa.io/en/latest/">virtualenv</a> encapsulates all aspect of a Python environment within a single directory tree. That means the Python packages you install for Home Assistant won’t interact with the rest of your system and vice-versa. It means a random upgrade for some other program on your computer won’t break Home Assitant, and it means you don’t need to install Python packages as root.</p>
|
||||
|
||||
<p>Virtualenvs are pretty easy to setup. This example will walk through one method of setting one up (there are certainly others). We’ll be using Debian in this example (as many Home Assistant users are running Raspbian on a Raspberry Pi), but all of the Python related steps should be the same on just about any platform.</p>
|
||||
|
||||
<h2><a class="title-link" name="step-0-install-some-dependencies" href="#step-0-install-some-dependencies"></a> Step 0: Install some dependencies</h2>
|
||||
|
||||
<div class="highlighter-coderay"><div class="CodeRay">
|
||||
<div class="code"><pre>sudo apt-get update
|
||||
sudo apt-get upgrade
|
||||
sudo apt-get install python-pip
|
||||
sudo pip install --upgrade virtualenv
|
||||
<div class="code"><pre>$ sudo apt-get update
|
||||
$ sudo apt-get upgrade
|
||||
$ sudo apt-get install python-pip
|
||||
$ sudo pip install --upgrade virtualenv
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -109,7 +109,7 @@ sudo pip install --upgrade virtualenv
|
|||
<p>This step is optional, but it’s a good idea to give services like Home Assistant their own user. It gives you more granular control over permissions, and reduces the exposure to the rest of your system in the event there is a security related bug in Home Assistant. This is a reasonably Linux oriented step, and will look different on other operating systems (or even other Linux distributions).</p>
|
||||
|
||||
<div class="highlighter-coderay"><div class="CodeRay">
|
||||
<div class="code"><pre>sudo adduser --system hass
|
||||
<div class="code"><pre>$ sudo adduser --system hass
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -119,41 +119,41 @@ sudo pip install --upgrade virtualenv
|
|||
<p>If you plan to use a Z-Wave controller, you will need to add this user to the <code>dialout</code> group</p>
|
||||
|
||||
<div class="highlighter-coderay"><div class="CodeRay">
|
||||
<div class="code"><pre>sudo usermod -G dialout -a hass
|
||||
<div class="code"><pre>$ sudo usermod -G dialout -a hass
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h2><a class="title-link" name="step-2-create-a-directory-for-home-assistant" href="#step-2-create-a-directory-for-home-assistant"></a> Step 2: Create a directory for Home Assistant</h2>
|
||||
|
||||
<p>This can be anywhere you want, but I generally put stuff related to servers in <code>/srv</code>. You also need to change the ownership of the directory to the user you created above (if you created one)</p>
|
||||
<p>This can be anywhere you want. AS example we put it in <code>/srv</code>. You also need to change the ownership of the directory to the user you created above (if you created one).</p>
|
||||
|
||||
<div class="highlighter-coderay"><div class="CodeRay">
|
||||
<div class="code"><pre>sudo mkdir /srv/hass
|
||||
sudo chown hass /srv/hass
|
||||
<div class="code"><pre>$ sudo mkdir /srv/hass
|
||||
$ sudo chown hass /srv/hass
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<p>## <a class="title-link" name="step-3-become-the-new-user" href="#step-3-become-the-new-user"></a> Step 3: Become the new user</p>
|
||||
|
||||
<p>This is obviously only necessary if you created a ‘hass’ user, but if you did, be sure to switch to that user whenever you install things in your virtualenv, otherwise you’ll end up with mucked up permissions.</p>
|
||||
<p>This is obviously only necessary if you created a <code>hass</code> user, but if you did, be sure to switch to that user whenever you install things in your virtualenv, otherwise you’ll end up with mucked up permissions.</p>
|
||||
|
||||
<div class="highlighter-coderay"><div class="CodeRay">
|
||||
<div class="code"><pre>sudo su -s /bin/bash hass
|
||||
<div class="code"><pre>$ sudo su -s /bin/bash hass
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>The ‘su’ command means ‘switch’ user. We use the ‘-s’ flag because the hass user is a system user and doesn’t have a default shell by default (to prevent attackers from being able to log in as that user).</p>
|
||||
<p>The <code>su</code> command means ‘switch’ user. We use the ‘-s’ flag because the <code>hass</code> user is a system user and doesn’t have a default shell by default (to prevent attackers from being able to log in as that user).</p>
|
||||
|
||||
<h2><a class="title-link" name="step-4-set-up-the-virtualenv" href="#step-4-set-up-the-virtualenv"></a> Step 4: Set up the virtualenv</h2>
|
||||
|
||||
<p>All this step does is stick a Python environment in the directory we’re using. That’s it. It’s just a directory. There’s nothing ‘special’ about it, and it is entirely self-contained.</p>
|
||||
|
||||
<p>It will include a ‘bin’ directory, which will contain all the executables used in the virtualenv (including hass itself). It also includes a script called ‘activate’ which we will use to activate the virtualenv.</p>
|
||||
<p>It will include a <code>bin</code> directory, which will contain all the executables used in the virtualenv (including hass itself). It also includes a script called <code>activate</code> which we will use to activate the virtualenv.</p>
|
||||
|
||||
<div class="highlighter-coderay"><div class="CodeRay">
|
||||
<div class="code"><pre>virtualenv -p python3 /srv/hass
|
||||
<div class="code"><pre>$ virtualenv -p python3 /srv/hass
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -161,36 +161,36 @@ sudo chown hass /srv/hass
|
|||
<h2><a class="title-link" name="step-5-activate-the-virtualenv" href="#step-5-activate-the-virtualenv"></a> Step 5: Activate the virtualenv</h2>
|
||||
|
||||
<div class="highlighter-coderay"><div class="CodeRay">
|
||||
<div class="code"><pre>source /srv/hass/bin/activate
|
||||
<div class="code"><pre>$ source /srv/hass/bin/activate
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>After that, your prompt should include ‘(hass)’.</p>
|
||||
<p>After that, your prompt should include <code>(hass)</code>.</p>
|
||||
|
||||
<h2><a class="title-link" name="step-6-install-home-assistant" href="#step-6-install-home-assistant"></a> Step 6: Install Home Assistant</h2>
|
||||
|
||||
<p>Once your virtualenv has been activated, you don’t need to <code>sudo</code> any of your pip commands. Pip will be installing things in the virtualenv, which our ‘hass’ user has permission to modify.</p>
|
||||
<p>Once your virtualenv has been activated, you don’t need to <code>sudo</code> any of your <code>pip</code> commands. <code>pip</code> will be installing things in the virtualenv, which the <code>hass</code> user has permission to modify.</p>
|
||||
|
||||
<div class="highlighter-coderay"><div class="CodeRay">
|
||||
<div class="code"><pre>(hass)pip3 install --upgrade homeassistant
|
||||
<div class="code"><pre>(hass)$ pip3 install --upgrade homeassistant
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>And that’s it… you now have Home Assistant installed, and you can be sure that every bit of it is contained in /srv/hass</p>
|
||||
<p>And that’s it… you now have Home Assistant installed, and you can be sure that every bit of it is contained in <code>/srv/hass</code>.</p>
|
||||
|
||||
<h2><a class="title-link" name="finally-run-home-assistant" href="#finally-run-home-assistant"></a> Finally… Run Home Assistant</h2>
|
||||
|
||||
<p>There are two ways to launch Home Assistant. If you are ‘in’ the virtualenv, you can just run <code>hass</code> and it will work as normal. If the virtualenv is not activated, you just use the <code>hass</code> executable in the <code>bin</code> directory mentioned earlier. There is one caveat… Because Home Assistant stores it’s configuration in the user’s home directory, we need to be the user <code>hass</code> user or specify the configuration with <code>-c</code>.</p>
|
||||
<p>There are two ways to launch Home Assistant. If you are <strong>in</strong> the virtualenv, you can just run <code>hass</code> and it will work as normal. If the virtualenv is not activated, you just use the <code>hass</code> executable in the <code>bin</code> directory mentioned earlier. There is one caveat… Because Home Assistant stores it’s configuration in the user’s home directory, we need to be the user <code>hass</code> user or specify the configuration with <code>-c</code>.</p>
|
||||
|
||||
<div class="highlighter-coderay"><div class="CodeRay">
|
||||
<div class="code"><pre>sudo -u hass -H /srv/hass/bin/hass
|
||||
<div class="code"><pre>$ sudo -u hass -H /srv/hass/bin/hass
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>The ‘-H’ flag is important. It sets the <code>$HOME</code> environment variable to <code>/home/hass</code> so <code>hass</code> can find its configuration.</p>
|
||||
<p>The <code>-H</code> flag is important. It sets the <code>$HOME</code> environment variable to <code>/home/hass</code> so <code>hass</code> can find its configuration.</p>
|
||||
|
||||
<h2><a class="title-link" name="upgrading-home-assistant" href="#upgrading-home-assistant"></a> Upgrading Home Assistant</h2>
|
||||
|
||||
|
@ -204,7 +204,7 @@ sudo chown hass /srv/hass
|
|||
|
||||
<p>If you want to use Z-Wave devices, you will need to install <code>python-openzwave</code> in your virtualenv. This requires a small tweak to the instructions on home-assistant.io</p>
|
||||
|
||||
<p>Install the dependencies as normal (Note: you’ll need to do this as your normal user, since ‘hass’ isn’t a sudoer).</p>
|
||||
<p>Install the dependencies as normal (Note: you will need to do this as your normal user, since <code>hass</code> isn’t a sudoer).</p>
|
||||
|
||||
<div class="highlighter-coderay"><div class="CodeRay">
|
||||
<div class="code"><pre>$ sudo apt-get install cython3 libudev-dev python3-sphinx python3-setuptools
|
||||
|
@ -220,7 +220,7 @@ sudo chown hass /srv/hass
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<p>Finally, get and install python-openzwave</p>
|
||||
<p>Finally, get and install <code>python-openzwave</code>.</p>
|
||||
|
||||
<div class="highlighter-coderay"><div class="CodeRay">
|
||||
<div class="code"><pre>(hass)$ mkdir /srv/hass/src
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue