How to Install Healthchecks on Debian Latest
Healthchecks is a platform that monitors scheduled jobs and services. It sends notifications to your email or other channels to help you identify when a job fails to run. The self-hosted version of Healthchecks can be installed on your Debian latest system to keep track of your scheduled jobs on your own infrastructure.
In this tutorial, we will walk you through the process of installing Healthchecks on Debian Latest. We assume you have a basic knowledge of Linux and familiarity with the command-line interface.
Prerequisites
Before we begin, ensure you have the following prerequisites:
- A Debian latest system with sudo privileges.
- Python 3.7 or later.
- pip3 package installer.
Step 1: Update and Upgrade Debian System
Before installing any software, it's essential to have an up-to-date system. Launch your terminal and run the commands below:
sudo apt update
sudo apt upgrade -y
This command will update your package list and upgrade your system packages.
Step 2: Install Required Packages
In this step, you need to install essential dependencies required by Healthchecks. Run the following command on your terminal:
sudo apt install nginx postgresql redis
- nginx: A web server that will serve the Healthchecks web dashboard.
- postgresql: A relational database management system that Healthchecks uses to store data.
- redis: A tool for managing queues that Healthchecks uses to manage job scheduling.
When prompted, enter "Y" to install the packages.
Step 3: Install Healthchecks
In this step, we will install Healthchecks on your Debian latest system.
Create the Healthchecks user:
sudo useradd --system --user-group healthchecksThe above command creates a new system user, which will run the Healthchecks service with restricted privileges.
Clone the Healthchecks repository:
sudo git clone https://github.com/healthchecks/healthchecks.git /opt/healthchecksThis command downloads the source code of the Healthchecks application into the
/opt/healthchecksdirectory.Change the directory permissions:
sudo chown -R healthchecks:healthchecks /opt/healthchecksThe command changes the ownership of the
/opt/healthchecksdirectory to thehealthchecksuser we previously created.Install the
virtualenvpackage:sudo apt install python3-virtualenvThe
virtualenvpackage is used to create a virtual environment for Healthchecks, which isolates the application from the underlying system.Create the virtual environment:
sudo -Hu healthchecks bash -c 'cd /opt/healthchecks && virtualenv hc-venv && source hc-venv/bin/activate && pip3 install -r requirements.txt'This command creates a virtual environment for the Healthchecks application, installs the required dependencies, and activates the virtual environment.
Create the
.envfile:sudo -Hu healthchecks bash -c 'cd /opt/healthchecks && cp contrib/docker/.env.example .env'This command creates a copy of the
.env.examplefile and renames it to.env, which will store the Healthchecks configuration.
Step 4: Configure Healthchecks
In this step, we will configure Healthchecks with a PostgreSQL database and Nginx as the web server.
Create a database in PostgreSQL:
sudo su postgres psql postgres=# CREATE DATABASE healthchecks; postgres=# CREATE USER healthchecks WITH PASSWORD 'your_password_here'; postgres=# GRANT ALL PRIVILEGES ON DATABASE healthchecks TO healthchecks; postgres=# \q exitThe above commands create a new database called
healthcheckswith a userhealthchecksand grants it all privileges.Edit the
.envconfiguration file:sudo nano /opt/healthchecks/.envUpdate the following lines in the
.envfile:DB_URL=postgres://healthchecks:your_password_here@localhost/healthchecks SECRET_KEY=some-secret-key-hereReplace
your_password_herewith the password you used for the PostgreSQL user.Set a random
SECRET_KEY.Create an Nginx configuration file:
sudo nano /etc/nginx/sites-available/healthchecks.conf
Paste the following code in the editor:
server {
listen 80;
server_name healthchecks.example.com; # Replace with your domain name.
access_log /var/log/nginx/healthchecks_access.log;
error_log /var/log/nginx/healthchecks_error.log;
location / {
# proxy_pass http://localhost:8000; # Uncomment this line for using Healthchecks with Gunicorn server.
proxy_pass http://unix:/opt/healthchecks/hc.sock;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /static/ {
root /opt/healthchecks;
expires 30d;
access_log off;
}
location /favicon.ico {
alias /opt/healthchecks/static/img/favicon.ico;
}
}
Replace healthchecks.example.com with your domain name or server IP address.
Enable the Nginx site and restart Nginx:
sudo ln -s /etc/nginx/sites-available/healthchecks.conf /etc/nginx/sites-enabled/ sudo systemctl restart nginxRun Healthchecks:
cd /opt/healthchecks/ source /opt/healthchecks/hc-venv/bin/activate ./manage.py migrate ./manage.py createsuperuser ./manage.py collectstatic --noinput ./manage.py generate_tries gunicorn hc.wsgi:application --bind unix:/opt/healthchecks/hc.sock --workers 4 --worker-class gthread --threads 4The above command runs the
migratecommand to create the database schema, generates a superuser account, and creates a static asset folder. It also generates the initial data required for Healthchecks to function. Finally, the command starts the Gunicorn server on a unix socket.Note: You can also use the
systemdunit file andSupervisorto manage the Healthchecks service. You can find more information on the official documentation page.
Step 5: Accessing Healthchecks
You can now access Healthchecks on your web browser by visiting http://healthchecks.example.com/ or http://your_server_IP/. Replace healthchecks.example.com or your_server_IP with your domain name or server IP, respectively. You should see the Healthchecks login form. You can sign in with the superuser account credentials you generated earlier.
Conclusion
In this tutorial, we installed Healthchecks on Debian latest, configured PostgreSQL as the database, and Nginx as the webserver. You now have a running instance of Healthchecks, which you can use to monitor your scheduled jobs and services.