Follow

How to add tools or scripts into a Resource Manager 5.x Docker Container

Applies To

  • Zenoss Resource Manager 5.x

Summary

It is often useful to run scripts or troubleshooting tools in docker containers. This KB describes the methods necessary to modify Resource Manager (RM) Docker containers to run scripts or tools and enable them to persist.

Because Docker containers are initiated from a base image, they are stateless. This means any modifications made to the container are lost upon restart unless those changes are incorporated into the image. Changes include adding or installing scripts and tools within the container.

The method used to modify the container to make the modifications available to the Zenoss RM depends on how permanent the changes need to be. The choices for permanency include:

  • Temporary -
    the script or tool exists only until the container restarts
  • Semi-permanent -
    the script or tool is replicated to all other containers and persists on container restart but is lost at next upgrade
  • Permanent -
    the script or tool persists following upgrade (Note: although these will be available to any host, there are exceptions depending on use case)

For additional information on containers, see the KB article titled Virtualization and Docker Containerization for Poets.

Procedures

The following procedures explain how to copy tools or scripts into a container and make them persist, depending on the permanency requirements.

Note: The use case described in this KB suggests the zope container because toolbox requires access to zodb. The actual target will vary based on your use case. Contact Zenoss support if you are unsure which service needs access to the custom tool.

Temporary Tool or Script

This procedure makes the tool or script available only temporarily, it will not persist when the container restarts or following an upgrade.

To make the tool or script persist until an upgrade (semi-permanent), proceed instead to the next section, Semi-Permanent Tool or Script.

To make the tool or script persist following an upgrade, proceed instead to the next section, Permanent Tool or Script.

  1. Move the tool or script into the container from a server running SSH:
    1. Become root if necessary:
      sudo - su
    2. Attach to the container, for example:
      serviced service attach zope/0
    3. Become the zenoss user:
      su - zenoss
    4. SCP the file into the container. For example toolbox.zip:
      scp user@remote_server:~/toolbox.zip .

      NOTE: It is also possible to use rsync to copy the files to the host..

  2. Execute the script or install the tool.
    NOTE: Some tools might require installation. For example to install the toolbox utility:
    1. Change into the directory where the toolbox utility is located.
    2. Install the toolbox utility:
      easy_install zenoss_toolbox.zip

Semi-Permanent Tool or Script

The following procedure makes the tool, script or utility semi-permanent in the container(s). This means it is replicated to all other containers and persists upon container restart but is lost at the next upgrade.

To make the tool or script persist following an upgrade, proceed instead to the next section, Permanent Tool or Script.

  1. Shell into a new container and move the tool or script into the container from a server running SSH:
    1. Become root if necessary:
      sudo - su
    2. Shell into a new container to create it based on an existing container. For example, spawn the new container from the existing zope container:
      mynew=InstallToolbox
      serviced service shell -s $mynew -i zope
    3. Become the zenoss user:
      su - zenoss
    4. SCP the file into the container. For example, toolbox.zip:
      scp user@remote_server:~/toolbox.zip .

    NOTES:

    • It is also possible to use rsync to copy the files to the host.
    • Docker enables a feature that files located in the directory where the new container is spawned from are also available within the container directory /mnt/pwd directory.

  2. Execute the script or install the tool.
    NOTE: Some tools might require installation. For example to install the toolbox utility:
    1. Change into the directory where the toolbox utility is located.
    2. Install the toolbox utility:
      easy_install zenoss_toolbox.zip
  3. Exit the zenoss user:
    exit
  4. Exit the container:
    exit
  5. Commit the container where the changes have been made, for example commit the mynew container:
    serviced snapshot commit $mynew
  6. Restart the service so the change becomes effective in all containers, for example, zope:
    serviced service restart zope

Permanent Tool or Script

The following procedure makes tools or scripts permanent in the container(s) by placing them within a special DFS directory. This special directory mounts to the containers and survives upgrade. This means any tool or script installed in this directory is replicated to all other containers, persists upon container restart and survives upgrade (Note: only for single host instances of 5.x)

  1. Shell into a new container:
    1. Become root if necessary:
      sudo - su
    2. Shell into a new container to create it based on an existing container. For example, spawn the new container from the existing zope container:
      mynew=InstallToolbox
      serviced service shell -s $mynew -i zope
    3. Become the zenoss user:
      su - zenoss
  2. Create a directory within the DFS directory /opt/zenoss/var/ext for your tool or script. For example:
    mkdir /opt/zenoss/var/ext/my_new_dir
  3. Copy or install your tool or script into the new directory. For example:
    1. Change into the new directory:
      cd /opt/zenoss/var/ext/my_new_dir
    2. Copy or install the tool or script into that directory. For example:
      scp user@remote_server:~/toolbox.zip .
      easy_install toolbox.zip
  4. Exit the zenoss user:
    exit
  5. Exit the container:
    exit
  6. Commit the container where the changes have been made, for example commit the mynew container:
    serviced snapshot commit $mynew
  7. Restart the service so the change becomes effective in all containers, for example, zope:
    serviced service restart zope

Adding the tool or script to the special DFS directory ensures it will persist following an upgrade.

After an Upgrade

Following an upgrade, it is necessary to:

  • Reapply patches (via quilt for example)
  • Retrieve any stored customized scripts from the /opt/zenoss/var/ext/my_new_dir
  • Reinstall any previously installed tools from the /opt/zenoss/var/ext/my_new_dir
Was this article helpful?
2 out of 3 found this helpful

Comments

Powered by Zendesk