Skip to content

root: handle SIGHUP and SIGUSR2, healthcheck gunicorn - #6630

Merged
rissson merged 5 commits into
mainfrom
gunicorn-health
Sep 27, 2023
Merged

rissson merged 5 commits into
mainfrom
gunicorn-health

Conversation

@rissson

@rissson rissson commented Aug 25, 2023

Copy link
Copy Markdown
Member

Details

Extracted from #5415


Checklist

  • Local tests pass (ak test authentik/)
  • The code has been formatted (make lint-fix)

If an API change has been made

  • The API schema has been updated (make gen-build)

If changes to the frontend have been made

  • The code has been formatted (make web)
  • The translation files have been updated (make i18n-extract)

If applicable

  • The documentation has been updated
  • The documentation has been formatted (make website)

This is the first step to handle configuration reloading. With those
changes, it is already possible to do so, by sending a SIGUSR2 signal to
the Go server process. The next step would be to watch for changes to
configuration files and call the Restart function of the GoUnicorn
instance.

SIGHUP is catched by the go server and forwarded as-is to gunicorn,
which causes it to restart its workers. However, that does not trigger
a reload of the Django settings, probably because they are already
loaded in the master, before creating any of the worker instances.

SIGUSR2, however, can be used to spawn a new gunicorn master process,
but handling it is a bit trickier. Please refer to Gunicorn's
documentation[0] for details, especially the "Upgrading to a new binary
on the fly" section.

As we are now effectively killing the gunicorn processed launched by the
server, we need to handle some sort of check to make sure it is still
running. That's done by using the already existing healthchecks, making
them useful not only for the application start, but also for its
lifetime. If a check is failed too many times in a given time period,
the gunicorn processed is killed (if necessary) and then restarted.

[0] https://docs.gunicorn.org/en/20.1.0/signals.html

Other relevant links and documentation:

Python library handling the processing swaping upon a SIGUSR2:
https://github.com/flupke/rainbow-saddle/

Golang cannot easily check if a process exists on Unix systems:
golang/go#34396

Signed-off-by: Marc 'risson' Schmitt <[email protected]>
@rissson
rissson requested a review from BeryJu August 25, 2023 19:00
@rissson
rissson requested a review from a team as a code owner August 25, 2023 19:00
@rissson rissson self-assigned this Aug 25, 2023
@netlify

netlify Bot commented Aug 25, 2023 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit a310649
🔍 Latest deploy log https://app.netlify.com/sites/authentik-storybook/deploys/6514102429a8f9000803d38b
😎 Deploy Preview https://deploy-preview-6630--authentik-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines 37 to 39
started: false,
killed: false,
alive: false,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would an enum be better here?

@codecov

codecov Bot commented Aug 25, 2023 •

Copy link
Copy Markdown

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (b15002a) 92.71% compared to head (a310649) 92.71%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6630   +/-   ##
=======================================
  Coverage   92.71%   92.71%           
=======================================
  Files         567      567           
  Lines       27965    27965           
=======================================
  Hits        25925    25925           
  Misses       2040     2040           
Flag Coverage Δ
e2e 51.13% <ø> (+0.02%) ⬆️
integration 26.27% <ø> (ø)
unit 89.60% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions

github-actions Bot commented Aug 25, 2023 •

Copy link
Copy Markdown
Contributor

authentik PR Installation instructions

Instructions for docker-compose

Add the following block to your .env file:

AUTHENTIK_IMAGE=ghcr.io/goauthentik/dev-server
AUTHENTIK_TAG=gh-gunicorn-health-1695814484-a310649
AUTHENTIK_OUTPOSTS__CONTAINER_IMAGE_BASE=ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s

For arm64, use these values:

AUTHENTIK_IMAGE=ghcr.io/goauthentik/dev-server
AUTHENTIK_TAG=gh-gunicorn-health-1695814484-a310649-arm64
AUTHENTIK_OUTPOSTS__CONTAINER_IMAGE_BASE=ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s

Afterwards, run the upgrade commands from the latest release notes.

Instructions for Kubernetes

Add the following block to your values.yml file:

authentik:
    outposts:
        container_image_base: ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s
image:
    repository: ghcr.io/goauthentik/dev-server
    tag: gh-gunicorn-health-1695814484-a310649

For arm64, use these values:

authentik:
    outposts:
        container_image_base: ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s
image:
    repository: ghcr.io/goauthentik/dev-server
    tag: gh-gunicorn-health-1695814484-a310649-arm64

Afterwards, run the upgrade commands from the latest release notes.

@BeryJu BeryJu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to give this some more testing in dogfooding before we actually ship it, let's merge it after 2023.8 is out

@rissson

rissson commented Aug 26, 2023

Copy link
Copy Markdown
Member Author

I'll convert to draft to prevent accidental merging.

@rissson
rissson marked this pull request as draft August 26, 2023 00:39
@rissson
rissson marked this pull request as ready for review August 29, 2023 19:17
Signed-off-by: Jens Langhammer <[email protected]>

# Conflicts:
#	cmd/server/server.go
#	internal/gounicorn/gounicorn.go
@rissson

rissson commented Sep 11, 2023

Copy link
Copy Markdown
Member Author

@BeryJu when merging, let's not lose the commit message from e934be4

@rissson rissson mentioned this pull request Sep 21, 2023
1 of 4 tasks
@BeryJu
BeryJu requested review from a team as code owners September 26, 2023 22:12

@BeryJu BeryJu left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rissson please have a look at the latest commit that does some minor changes, aside from that we can merge (we should probably also add documentation for this somewhere)

@netlify

netlify Bot commented Sep 26, 2023 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik ready!

Name Link
🔨 Latest commit a310649
🔍 Latest deploy log https://app.netlify.com/sites/authentik/deploys/6514102439a2730008d15ec6
😎 Deploy Preview https://deploy-preview-6630--authentik.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 95 (🔴 down 1 from production)
Accessibility: 90 (no change from production)
Best Practices: 100 (no change from production)
SEO: 80 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@rissson

rissson commented Sep 27, 2023

Copy link
Copy Markdown
Member Author

@rissson please have a look at the latest commit that does some minor changes, aside from that we can merge (we should probably also add documentation for this somewhere)

LGTM

@rissson
rissson enabled auto-merge (squash) September 27, 2023 11:21
@rissson
rissson merged commit 4a434d5 into main Sep 27, 2023
@rissson
rissson deleted the gunicorn-health branch September 27, 2023 11:34
kensternberg-authentik added a commit that referenced this pull request Sep 27, 2023
* main: (41 commits)
  root: fix missing /lifecycle in path
  website/blog: add info-block to blog about m2m (#7002)
  root: handle SIGHUP and SIGUSR2, healthcheck gunicorn (#6630)
  flows: stage_invalid() makes flow restart depending on invalid_response_action setting (#6780)
  core: bump psycopg from 3.1.11 to 3.1.12 (#6997)
  core: bump pydantic from 2.4.0 to 2.4.1 (#6998)
  web: bump the sentry group in /web with 2 updates (#6999)
  web: bump pyright from 1.1.328 to 1.1.329 in /web (#7000)
  website/blog: improved sentence (#6995)
  website/blog: fix missing link in m2m post (#6994)
  web/user: fix incorrect link to admin interface (#6993)
  root: disable APPEND_SLASH (#6928)
  root: replace boj/redistore with vendored version of rbcervilla/redisstore (#6988)
  sources/ldap: add default property mapping to mirror directory structure (#6990)
  website/blogs: Blog about m2m (#6974)
  root: make Celery worker concurrency configurable (#6837)
  root: make postgres connection in makefile customizable (#6977)
  core: prevent self-impersonation (#6885)
  web: bump @typescript-eslint/parser from 6.7.2 to 6.7.3 in /web (#6984)
  core: bump pydantic from 2.3.0 to 2.4.0 (#6979)
  ...
kensternberg-authentik added a commit that referenced this pull request Sep 29, 2023
* main: (50 commits)
  web/admin: invitation stage: default "continue without invitation" to false
  core: bump pydantic from 2.4.1 to 2.4.2 (#7014)
  website: bump postcss from 8.4.30 to 8.4.31 in /website (#7015)
  internal: fix redis session store (#7011)
  web: bump rollup from 3.29.3 to 3.29.4 in /web (#7009)
  core: bump github.com/prometheus/client_golang from 1.16.0 to 1.17.0 (#7007)
  web: bump the esbuild group in /web with 2 updates (#7005)
  website: bump react-tooltip from 5.21.4 to 5.21.5 in /website (#7006)
  core: bump github.com/redis/go-redis/v9 from 9.2.0 to 9.2.1 (#7008)
  root: fix missing /lifecycle in path
  website/blog: add info-block to blog about m2m (#7002)
  root: handle SIGHUP and SIGUSR2, healthcheck gunicorn (#6630)
  flows: stage_invalid() makes flow restart depending on invalid_response_action setting (#6780)
  core: bump psycopg from 3.1.11 to 3.1.12 (#6997)
  core: bump pydantic from 2.4.0 to 2.4.1 (#6998)
  web: bump the sentry group in /web with 2 updates (#6999)
  web: bump pyright from 1.1.328 to 1.1.329 in /web (#7000)
  website/blog: improved sentence (#6995)
  website/blog: fix missing link in m2m post (#6994)
  web/user: fix incorrect link to admin interface (#6993)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants