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:

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

When prompted, enter "Y" to install the packages.

Step 3: Install Healthchecks

In this step, we will install Healthchecks on your Debian latest system.

  1. Create the Healthchecks user:

    sudo useradd --system --user-group healthchecks
    

    The above command creates a new system user, which will run the Healthchecks service with restricted privileges.

  2. Clone the Healthchecks repository:

    sudo git clone https://github.com/healthchecks/healthchecks.git /opt/healthchecks
    

    This command downloads the source code of the Healthchecks application into the /opt/healthchecks directory.

  3. Change the directory permissions:

    sudo chown -R healthchecks:healthchecks /opt/healthchecks
    

    The command changes the ownership of the /opt/healthchecks directory to the healthchecks user we previously created.

  4. Install the virtualenv package:

    sudo apt install python3-virtualenv
    

    The virtualenv package is used to create a virtual environment for Healthchecks, which isolates the application from the underlying system.

  5. 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.

  6. Create the .env file:

    sudo -Hu healthchecks bash -c 'cd /opt/healthchecks && cp contrib/docker/.env.example .env'
    

    This command creates a copy of the .env.example file 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.

  1. 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
    exit
    

    The above commands create a new database called healthchecks with a user healthchecks and grants it all privileges.

  2. Edit the .env configuration file:

    sudo nano /opt/healthchecks/.env
    
    • Update the following lines in the .env file:
    DB_URL=postgres://healthchecks:your_password_here@localhost/healthchecks
    SECRET_KEY=some-secret-key-here
    

    Replace your_password_here with the password you used for the PostgreSQL user.

    Set a random SECRET_KEY.

  3. 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.

  1. Enable the Nginx site and restart Nginx:

    sudo ln -s /etc/nginx/sites-available/healthchecks.conf /etc/nginx/sites-enabled/
    sudo systemctl restart nginx
    
  2. Run 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 4
    

    The above command runs the migrate command 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 systemd unit file and Supervisor to 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.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!