Supervisor & Daphne Configuration

Last Updated: October 2024

Supervisor is used to manage the NGINX and Daphne processes. As an ASGI server, Daphne is able to be run with multiple worker processes. It would be cumbersome to manage them individually. Using Supervisor, you will be able to use one command to start, stop, or restart the NGINX process and all of the Daphne processes.

1. Generate the Supervisor Configuration Files

One configuration file will be needed for NGINX and another for Daphne. Use the tethys gen command to generate default versions of these configuration files:

tethys gen nginx_service --overwrite
tethys gen asgi_service --overwrite

2. Review Supervisor Configuration Files

  1. Review the contents of the NGINX configuration file:

    vim <TETHYS_HOME>/nginx_supervisord.conf
    

    In particular, the locations of the log files. These may be useful for debugging later on.

  2. Review the contents of the Daphne (ASGI) configuration file:

    vim <TETHYS_HOME>/asgi_supervisord.conf
    

    In particular, verify the following:

    • The TETHYS_HOME variable is set correctly

    • The directory is the path to the directory where Tethys Platform is installed (usually the site-packages directory of your tethys conda environment).

    • Adjust the numprocs to the number of Daphne processes you would like it to run.

    • Note the location of the stdout_logfile.

    • Note the location of the process file after the -u argument of the daphne command in the command parameter. The default value for the process file should be something like: /run/tethys_asgi%(process_num)d.sock

Tip

Replace <TETHYS_HOME> with the path to the Tethys home directory as noted in Portal Configuration section.

3. Create Run Directory

Verify that the directory where the ASGI process files will be created exists. You noted this directory when verifying the asgi_supervisor.conf file in the previous step. For example, if the path in asgi_supervisor.conf was defined as /run/asgi/tethys_asgi%(process_num)d.sock, then you would need to ensure that the /run/asgi directory exists and is owned by the NGINX_USER or APACHE_USER.

Note

If the process file is specified to be created at the root /run directory (e.g.: /run/tethys_asgi%(process_num)d.sock), then no action is required for this step.

5. Modify supervisord.conf (Rocky Linux Only)

For Rocky Linux systems, modify supervisord.conf to recognize our configuration files:

Rocky Linux:

sudo sed -i '$ s@$@ /etc/supervisord.d/*.conf@' "/etc/supervisord.conf"

6. Setup Tethys Log

Create the log file in the location where supervisor expects it to be (see last item in 2.2).

  1. Create a directory and file for Daphne/Django to write the Tethys Portal logs:

    sudo mkdir -p /var/log/tethys
    sudo touch /var/log/tethys/tethys.log
    
  2. Change the directory to be owned by the NGINX user:

    sudo chown -R <NGINX_USER|APACHE_USER> /var/log/tethys
    

    Tip

    Replace <NGINX_USERR|APACHE_USER> with the name of the user noted in the NGINX Configuration or Apache Configuration.

7. Reload the Configuration

Once you have finished the configuration steps, it is necessary to instruct Supervisor to reread and update as follows so that it loads our new Supervisor configurations:

sudo supervisorctl reread
sudo supervisorctl update

Note

This step needs to be performed anytime you make changes to the nginx_supervisord.conf or asgi_supervisord.conf