Developer Journal: 02 May 2020

Posted on Sat 02 May 2020 in dev-journal

The goal for today is to clean up how site log files are stored

First, creating a subdirectory for each site in the /var/log/uwsgi/ folder will help keep things organized. This directory should be made when the site is created. The permissions will also need to be updated on the subdirectory so the conveyor user can write files to it.

First I'm going to create a couple of simple tests

The first will make sure that the create site calls the correct function to ensure the subdirectory is created.

def test_create_site_calls_create_log_subdirectory(self, 
    mock_create_log_subdirectory.return_value = ""
    site = Site.query.get(1)
    site.site_type = SiteTypeEnum.static.value
    provisioner = Provisioner(
    provisioner.create_site(site, "aoeu", "iso")
def test_create_log_subdirectory_commands(self):
    provisioner = Provisioner(
    cmd = provisioner.get_log_subdirectory_command("")
    expected = ["mkdir /var/log/uwsgi/",
                "chown conveyor /var/log/uwsgi/"]
    self.assertEqual(expected, cmd)

Then create the function that will actually do the work

def get_log_subdirectory_command(self, domain):
    path = '/var/log/uwsgi/{0}'.format(domain)
    commands = [
        'mkdir {0}'.format(path),
        'chown conveyor {0}'.format(path),
    return commands

Create the subdirectory on site deploys to keep backwards compatibility until a script is created to to this on all sites

if site.site_type is not SiteTypeEnum.static.value:
    # create log sub directory for site
    # TODO this is only needed until a script is created to
    # create this subdirectory for each site that been created on all
    # servers. Currently this will be done when a site is created,
    # but this allows for compatibility of the new site wsgi config
    # for logs.
  • A further improvement will be to configure logs to consolidate after a period of time