escripts/inspector/README.md
Eugene Amos 41278c17a5 Inspector
> Updating file name to `inspector_qbitt`
2023-12-04 13:33:06 -08:00

4.0 KiB

Inspector

This will monitor the health of the qbittorrent container. If the health status is anything other than "Healthy", it will reboot the container after a set amount of time. After the container has been rebooted, the cool down period will start to give the container time to normalize. During the cool down, all actions will be paused for a specified amount of time.

Prerequisites

The following modules are required for the script to function. They will need to be installed first. Python ships with some core modules but others will need to be installed separately.

Standard Python Library Modules:

This script uses Python and multiple add on modules.

  • time: This is a part of the standard Python library, used for handling time-related tasks.

  • os: Also part of the standard library, it provides a way of using operating system dependent functionality.

  • datetime: This module supplies classes for manipulating dates and times, and it's included in the standard library.

  • Logging: This is used for logging events and messages and is included in the standard library.

  • logging.handlers: This is a part of the logging module, offering various handlers for logging.

Modules that Need to be Installed:

  • colorlog: This is an external library for colored logging output. You need to install it separately using pip.

  • docker: This module is used to interact with Docker. It is not part of the standard library and needs to be installed separately.

  • requests: A popular HTTP library for Python, used for making HTTP requests. This is not included in the standard library and must be installed separately.

To install the external modules you will first need PIP installed on your server. PIP is the package manager for Python.

  1. See if pip is already installed. Open a terminal and type:

    pip -V
    
  2. If not, install it.

    python get-pip.py
    
  3. Once pip is installed you can install the external modules.

    pip install colorlog docker requests
    

Folder Structure

If you have not done so already, create a new folder called scripts in your ~home folder. This is where all your scripts will go.

Inside your scripts folder create a new folder called inspector

When done your folders structure should look like this: /home/[username]/scripts/inspector

Script

Get the source code from this repo and save it as inspector_qbitt.py in the inspector folder created in the previous step.

Next we need to change the permissions of this file so that the server can read it.

  1. Right click on inspector_qbitt.py then Properties.

  2. Click on Permissions tab at top.

  3. Make sure Owner & Group reflect your username with Read and Write access to all.

  4. Check the Execute box to allow executing the file as a program.

  5. Close out the window.

Run

Now we need to test and run the script.

Make sure your terminal is open to the location of the inspector_qbitt.py file. Should be ~/scripts/inspector

Normally to run a Python script will would use python3 inspector_qbitt.py

This will still work but because we have shebang set in the script we can just use ./inspector_qbitt.py

You should now see [INFO] log with the status of the qbittorrent container. In the script we set the run time with interval_seconds = 60. This setting tells the script to check the health of the container every minute.

Automation

Now the script will need to be automated so that the qbittorrent docker will always reboot when needed. See system services to do so.