94 lines
4.0 KiB
Markdown
94 lines
4.0 KiB
Markdown
<h1 align="center">Inspector</h1>
|
|
|
|
<p align="center">
|
|
This will monitor the health of the <strong>qbittorrent</strong> 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 <strong>cool down</strong> period will start to give the container time to normalize. During the <strong>cool down</strong>, all actions will be paused for a specified amount of time.
|
|
<br />
|
|
</p>
|
|
|
|
## 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:
|
|
|
|
* **<a href="https://pypi.org/project/colorlog/" target="_blank">colorlog:</a>** This is an external library for colored logging output. You need to install it separately using pip.
|
|
|
|
* **<a href="https://pypi.org/project/docker/" target="_blank">docker:</a>** This module is used to interact with Docker. It is not part of the standard library and needs to be installed separately.
|
|
|
|
* **<a href="https://pypi.org/project/requests/" target="_blank">requests:</a>** 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. **<a href="https://pypi.org/project/pip/" target="_blank">PIP</a>** is the package manager for Python.
|
|
|
|
1. See if **pip** is already installed. Open a terminal and type:
|
|
|
|
```bash
|
|
pip -V
|
|
```
|
|
|
|
2. If not, install it.
|
|
|
|
```bash
|
|
python get-pip.py
|
|
```
|
|
|
|
3. Once **pip** is installed you can install the external modules.
|
|
|
|
```bash
|
|
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 <a href="https://linuxhandbook.com/shebang" target="blank">shebang</a> 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 <a href="https://wiki.euronvault.com/services" target="blank">system services</a> to do so.
|