Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Kong - gracefully shutdown and ensure stopped before Envoy started; Envoy - check if ports 80 or 443 already in use #896

Merged
merged 4 commits into from
Feb 29, 2024

Conversation

thebengeu
Copy link
Member

fix: gracefully shutdown Kong on service stop

kong quit is already used within start-kong.sh for the all-in-one image. The sole purpose of start-kong.sh is to trap exit to run kong quit, perhaps stopsignal=QUIT in the supervisord config would be equivalent, but it ain't broke.

fix: ensure that Kong service is stopped before Envoy service is started

Per https://www.freedesktop.org/software/systemd/man/latest/systemd.unit.html#Before=, "Given two units with any ordering dependency between them, if one unit is shut down and the other is started up, the shutdown is ordered before the start-up. It doesn't matter if the ordering dependency is After= or Before=, in this case. It also doesn't matter which of the two is shut down, as long as one is shut down and the other is started up; the shutdown is ordered before the start-up in all cases. If two units have no ordering dependencies between them, they are shut down or started up simultaneously, and no ordering takes place."

Also ensures that Envoy will take priority over Kong on reboot if both are enabled.

fix: check if port 80 or 443 is already in use before starting Envoy

Envoy doesn't exit if it can't bind ports for all its listeners, and I couldn't find any configuration option to make it do so.

With this, auto-restart will kick in until both ports are no longer in use.

May not be necessary after the previous fix to ensure that Kong service is stopped before Envoy service is started, but doesn't hurt to have multiple defensive measures, since it's somewhat unexpected that Envoy doesn't exit on such failures.

The comment is now in `start-envoy.sh`.
`kong quit` is already used within `start-kong.sh` for the all-in-one image. The sole purpose of `start-kong.sh` is to trap exit to run `kong quit`, perhaps `stopsignal=QUIT` in the supervisord config would be equivalent, but it ain't broke.
Per https://www.freedesktop.org/software/systemd/man/latest/systemd.unit.html#Before=, "Given two units with any ordering dependency between them, if one unit is shut down and the other is started up, the shutdown is ordered before the start-up. It doesn't matter if the ordering dependency is After= or Before=, in this case. It also doesn't matter which of the two is shut down, as long as one is shut down and the other is started up; the shutdown is ordered before the start-up in all cases. If two units have no ordering dependencies between them, they are shut down or started up simultaneously, and no ordering takes place."

Also ensures that Envoy will take priority over Kong on reboot if both are enabled.
Envoy doesn't exit if it can't bind ports for all its listeners, and I couldn't find any configuration option to make it do so.

With this, auto-restart will kick in until both ports are no longer in use.

May not be necessary after the previous fix to ensure that Kong service is stopped before Envoy service is started, but doesn't hurt to have multiple defensive measures, since it's somewhat unexpected that Envoy doesn't exit on such failures.
@thebengeu thebengeu requested review from a team as code owners February 29, 2024 03:26
@thebengeu thebengeu merged commit 4a7ae57 into develop Feb 29, 2024
8 checks passed
@thebengeu thebengeu deleted the beng/envoy-check-ports branch February 29, 2024 05:54
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