Skip to content

Commit

Permalink
Merge pull request PalisadoesFoundation#4 from DangaRanga/2020-08
Browse files Browse the repository at this point in the history
Venv installation for bacnet agent
  • Loading branch information
palisadoes authored Aug 22, 2020
2 parents c0da0e0 + 35e11ea commit eac73a6
Show file tree
Hide file tree
Showing 9 changed files with 337 additions and 137 deletions.
47 changes: 5 additions & 42 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,6 @@ Configuration Guide

After installation, you will need to create a configuration file in a directory dedicated to ``pattoo``.

*********************************************
Setting the Configuration Directory Location
*********************************************

You must first set the location of the configuration directory by using the ``PATTOO_CONFIGDIR`` environmental variable. Here is how to do this from the Linux command line:

.. code-block:: bash
$ export PATTOO_CONFIGDIR=/path/to/configuration/directory
``pattoo`` applications will read the configuration files located in this directory when ``PATTOO_CONFIGDIR`` is set.

You can automatically set this variable each time you log in by adding these lines to your ``~/.bash_profile`` file.

.. code-block:: bash
export PATTOO_CONFIGDIR=/path/to/configuration/directory
Make sure that files in this directory are readable by the user that will be running ``pattoo`` agent daemons or scripts.

*********************
Configuration Options
Expand All @@ -38,18 +19,13 @@ Quick Method

Use the quick method if you are new to ``pattoo``.

Run the ``setup/configure.py`` script. It will prompt you for all configuration parameters. The defaults should be sufficient in most cases.
Run the ``setup/install.py`` script. The configuration values will be automatically set.

Here's the command to run:

.. code-block:: bash
setup/configure.py
Next Steps:

#. Run the installation script next as outlined in the :doc:`installation` guide.
#. You will now need to configure each agent individually. See the :doc:`agent` file for details on how to configure each type of agent.
$ sudo setup/install.py install configuration
Expert Method
=============
Expand All @@ -59,26 +35,13 @@ This section goes into configuration parameters in great detail.
Setting the Configuration Directory Location
---------------------------------------------

You must first set the location of the configuration directory by using the ``PATTOO_CONFIGDIR`` environmental variable. Here is how to do this from the Linux command line:

.. code-block:: bash
$ export PATTOO_CONFIGDIR=/path/to/configuration/directory
``pattoo`` applications will read the configuration files located in this directory when ``PATTOO_CONFIGDIR`` is set.

You can automatically set this variable each time you log in by adding these lines to your ``~/.bash_profile`` file.

.. code-block:: bash
export PATTOO_CONFIGDIR=/path/to/configuration/directory
By default, the configuration directory for all pattoo components is set to ``/etc/pattoo``, which is owned by the pattoo user

Make sure that files in this directory are readable by the user that will be running ``pattoo`` agent daemons or scripts.

Copy the Template to Your Configuration Directory
-------------------------------------------------

You can create your first ``pattoo.yaml`` configuration file by copying the template file in the ``examples/etc`` directory to the ``PATTOO_CONFIGDIR`` location.
You can create your first ``pattoo.yaml`` configuration file by copying the template file in the ``examples/etc`` directory to the ``/etc/pattoo`` location.

**NOTE:** If a ``/path/to/configuration/directory/pattoo.yaml`` file already exists in the directory then skip this step and edit the file according to the steps in following sections.

Expand Down Expand Up @@ -160,4 +123,4 @@ This table outlines the purpose of each configuration parameter
Agent Configuration
-------------------

You will now need to configure each agent individually. See the :doc:`agent` file for details on how to configure each type of agent.
You will now need to configure each agent individually. See the :doc:`agent` file for details on how to configure each type of agent.
52 changes: 34 additions & 18 deletions docs/installation.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Basic Installation
==================

Expand All @@ -9,7 +8,6 @@ Prerequisites

There are some software components that need to be installed prior to starting.

#. Install the prerequisite packages for the ``easysnmp`` python pip package. `Instructions can be found here. <https://easysnmp.readthedocs.io/en/latest/>`_
#. ``pattoo`` only runs on Python 3.6 or higher

Let's install the software.
Expand All @@ -27,41 +25,59 @@ Follow these steps.
$ mkdir -p /installation/parent/directory
$ cd /installation/parent/directory
#. Clone the repository to the parent directory using the ``git clone`` command. You can also choose to downloading and unzip the file in the parent directory. The repository can be found at: https://github.com/PalisadoesFoundation/pattoo-agent-bacnet
#. Clone the repository to the parent directory using the ``git clone`` command. You can also choose to downloading and unzip the file in the parent directory. The repository can be found at: https://github.com/PalisadoesFoundation/pattoo-agent-bacnet.

**Note** The repository should not be cloned to a directory with ``/home`` in its path

.. code-block:: bash
$ cd /installation/parent/directory
$ git clone https://github.com/PalisadoesFoundation/pattoo-agent-bacnet.git
#. Enter the ``/installation/parent/directory/pattoo-agent-bacnet`` directory with the ``pattoo-agent-bacnet`` files.
#. Install the required packages using the ``pip_requirements`` document in the ``pattoo-agent-bacnet`` root directory
4. Enter the ``/installation/parent/directory/pattoo-agent-bacnet`` directory with the ``pattoo-agent-bacnet`` files.
#. Install the below packages from the ``pip_requirements`` document in the ``pattoo-agent-bacnet`` root directory for a seamless installation using the

.. code-block:: bash
$ pip3 install --user --requirement pip_requirements.txt
$ pip3 install --user PattooShared
$ pip3 install --user virtualenv
#. Use the :doc:`configuration` to create a working configuration.
#. Follow the configuration steps for each daemon as explained in the :doc:`agent`.

Configuring systemd Daemons
Running the installation
---------------------------
Run the code block below to install the BACnet agent

You can also setup all the ``pattoo-agent-bacnet`` agents as system daemons by executing the ``setup/systemd/bin/install_systemd.py`` script.
.. code-block:: bash
You have to specify a ``--config_dir`` defining the configuration file directory.
$ sudo setup/install.py install all
**Note** The daemons are not enabled or started by default. You will have to do this separately using the ``systemctl`` command after running the script.
.. code-block:: bash
Stopping, Starting and Restarting daemons
------------------------------------------
By default, the installation starts the daemons, and restarts them if they are already running, however, if you desire to start, stop or restart the system daemon for the BACnet agent after the installation the following code blocks should assist:

$ sudo setup/systemd/bin/install_systemd.py --config_dir ~/GitHub/pattoo-agent-bacnet/etc
**Starting daemon**
.. code-block:: bash
$ sudo systemctl start pattoo_agent_bacnetipd.service
**Stopping daemon**
.. code-block:: bash
SUCCESS! You are now able to start/stop and enable/disable the following systemd services:
$ sudo systemctl stop pattoo_agent_bacnetipd.service
pattoo_agent_os_spoked.service
pattoo_agent_snmpd.service
pattoo_agent_os_autonomousd.service
pattoo_agent_os_hubd.service
**Restarting daemon**
.. code-block:: bash
$ sudo systemctl restart pattoo_agent_bacnetipd.service
Modifying configuration files
---------------------------------

Navigate to the ``/etc/pattoo`` directory to modify the ``pattoo_agent_bacnetipd.yaml`` configuration file for the BACnet agent using your desired text editor, with the code block below:

.. code-block:: bash
$
$ cd /etc/pattoo
2 changes: 1 addition & 1 deletion pip_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Pattoo packages

PattooShared==0.0.84
PattooShared==0.0.95

# Miscellaneous packages
PyYAML
Expand Down
71 changes: 71 additions & 0 deletions setup/_pattoo_agent_bacnet/checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""The checks necessary for a seamless installation."""
import os
import getpass
import sys
from _pattoo_agent_bacnet import shared


def venv_check():
"""Check if "virtualenv" is installed.
If virtualenv is not installed it gets automatically installed to the
user's default python path
Args:
None
Returns:
None
"""
# Check if virtualenv is installed
try:
import virtualenv
except ModuleNotFoundError:
print('virtualenv is not installed, installing virtualenv')
shared.run_script('pip3 install virtualenv==20.0.30')


def pattoo_shared_check():
"""Check if pattoo shared is installed.
If pattoo shared is not installed, it gets installed to the user's
default python path
Args:
None
Returns:
None
"""
# Try except to install pattoo shared
try:
import pattoo_shared
except ModuleNotFoundError:
print('PattooShared is missing, installing the latest version')
shared.run_script('pip3 install PattooShared')


def installation_checks():
"""Validate conditions needed to start installation.
Prevents installation if the script is not run as root and prevents
installation if script is run in a home related directory
Args:
None
Returns:
True: If conditions for installation are satisfied
"""
# Check user
if getpass.getuser() != 'travis':
if shared.root_check() is False:
shared.log('Please run the script with sudo to continue.')
# Check installation directory
if os.getcwd().startswith('/home'):
shared.log('''\
You cloned the repository in a home related directory, please clone in a\
non-home directory to continue''')
18 changes: 11 additions & 7 deletions setup/_pattoo_agent_bacnet/configure.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Configure the bacnet agent."""
import os
from _pattoo_agent_bacnet import shared as _shared
from pattoo_shared.installation import configure, shared
from pattoo_shared import files


def install():
def install(pattoo_home):
"""Start configuration process.
Args:
Expand All @@ -17,24 +18,27 @@ def install():
# Initialize key variables
if os.environ.get('PATTOO_CONFIGDIR') is None:
os.environ['PATTOO_CONFIGDIR'] = '{0}etc{0}pattoo'.format(os.sep)
config_directory = os.environ.get('PATTOO_CONFIGDIR')
config_dir = os.environ.get('PATTOO_CONFIGDIR')

bacnet_agent_dict = {
'polling_interval': 300,
}

# Attempt to create configuration directory
files.mkdir(config_directory)
files.mkdir(config_dir)

# Create the pattoo user and group
configure.create_user('pattoo', '/nonexistent', ' /bin/false', True)
if _shared.root_check() is True:
# Create the pattoo user and group
configure.create_user('pattoo', pattoo_home, '/bin/false', True)

# Attempt to change the ownership of the configuration directory
shared.chown(config_directory)
# Attempt to change the ownership of the config and home directories
shared.chown(config_dir)
shared.chown(pattoo_home)

config_file = configure.pattoo_config(
'pattoo_agent_bacnetipd',
config_directory,
config_dir,
bacnet_agent_dict)

configure.check_config(config_file, bacnet_agent_dict)
Loading

0 comments on commit eac73a6

Please sign in to comment.