Skip to content

Use infinite restarts for xsnippet-api.service #61

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

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions roles/xsnippet_api/templates/systemd.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Description = XSnippet API
After = network.target network-online.target
Copy link
Member

Choose a reason for hiding this comment

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

but the same thing could happen with database connection as well.

I'd suggest to add PostgreSQL to both Wants= and After=. So at least after the reboot we can preserve a proper ordering. Or maybe even Requires= if we want xsnippet-api not be started if PostgreSQL could not start.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that sounds good to me! I'm just not sure whether PostgreSQL unit actually waits until the process is ready to accept connections. So we might need infinite (or, at the very least, extra restarts) as defense in depth.

Copy link
Member

Choose a reason for hiding this comment

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

If it's linked with systemd, I'd expect it to report status "ready" once it's ready to accept connections.

Copy link
Member Author

@malor malor Dec 23, 2024

Choose a reason for hiding this comment

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

Ah, interesting! Didn't expect that! https://github.com/postgres/postgres/blob/578a7fe7b6f8484f6d7caa2fda288abb3fe87aa0/src/backend/postmaster/postmaster.c#L2317-L2325 confirms there is integration with systemd, indeed.

Let me add an explicit dependency on postgresql.service then.

Wants = network-online.target
StartLimitIntervalSec = 0

[Service]
WorkingDirectory = {{ xsnippet_api_root }}
Expand All @@ -11,6 +12,7 @@ Group = {{ xsnippet_api_user }}
ExecStartPre = {{ xsnippet_api_database_upgrade_bin }}
ExecStart = {{ xsnippet_api_bin }}
Restart = on-failure
RestartSec = 30

[Install]
WantedBy = multi-user.target
Loading