SlapOS Home SlapOS

    How To Add A Promise

    How to add a promise
    • Last Update:2023-08-21
    • Version:004
    • Language:en

    Agenda

    • Prerequisite
    • Add promise
    • Verification

    Promise is a key element to make sure your service is running as expected. This HowTo will explain how to add a new promise in the context of html5as-base software release.

    Here is the commit introducing this functionality to html5as Software release: commit diff.

    Prerequisites

    1. Read: Understanding SlapOS Promises
    2. Extend Monitor Stack

    Add Promise section

    Add a section for a monitoring promise in instance instance_html5as.cfg.in. We choose to add a [port-listening-promise] to check that the nginx service is listening port. It doesn't check if the service return an error or not.

    # Port Listening checking promise
    [port-listening-promise]
    <= monitor-promise-base
    promise = check_socket_listening
    name = nginx-port-listening.py
    config-host = ${html5as:ip}
    config-port = ${html5as:port}
    

    Add Section to processed parts

    Add port-listening-promise section to the list of processed parts in instance_html5as.cfg.in as no other processed parts depend on it.

    [buildout]
    parts =
        ...
        port-listening-promise
        ...

    Update md5sums

    Refer How To Move to md5sum automatic update to update md5sum:

    $ cd ~/srv/project/slapos/software/html5as-base
    $ ../../update-hash

    Validation

    1. Inspect the logs
    2. verify port connection promise

    Verify port connection promise

    To inspect the output of slapos node software:

    $ slapos node software --all

    To inspect the output of slapos node instance:

    $ slapos node instance --all
    

    Observe the log of slapos node Instance. It now contains the promise info at the end:

    2021-10-27 03:01:23 slapos[86186] INFO Checking slappart0 promises...
    2021-10-27 03:01:23 slapos[86186] INFO Checking promise nginx-port-listening.py...
    2021-10-27 03:01:23 nginx-port-listening.py[86186] INFO socket connection OK ('2001:67c:1254:f1::7692', 8086, 0, 0)

    If you face issues, please update your local branch first: 
    $ git stash
    $ git fetch
    $ git reset --hard origin/master
    $ git stash pop

    Then rerun the past commands