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

Install Consul Democracy 2.1.0 #221

Merged
merged 21 commits into from
Feb 20, 2024
Merged

Install Consul Democracy 2.1.0 #221

merged 21 commits into from
Feb 20, 2024

Conversation

javierm
Copy link
Member

@javierm javierm commented Sep 15, 2023

Objectives

  • Install the latest stable version of Consul Democracy

We're going to release version 2.1.0 with many changes that aren't
compatible with Consul Democracy 2.0.1, so we're creating this branch in
order to merge those changes and keep them there until we release Consul
Democracy 2.1.0.
@javierm javierm changed the base branch from debian_bookworm to master November 21, 2023 19:53
Senen and others added 16 commits November 21, 2023 20:55
…f nodejs

Note we aren't installing the `master` branch (for now) because that
branch requires configuring Puma with systemd. Instead, we're using the
last commit which still uses Puma as a daemon.
Consul Democracy has added a `.node-version` file in version 2.1.0, and
now it installs the version defined there when deploying with Capistrano
and installs NPM packages for that version.

So we're doing the same when running the installer.
```
[DEPRECATION WARNING]: "include" is deprecated, use include_tasks/import_tasks instead. See https://docs.ansible.com/ansible-core/2.15/user_guide/playbooks_reuse_includes.html for
details. This feature will be removed in version 2.16. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
```
We found nodejs binaries from `nodejs.org/dist` sometimes are not
available or takes to long to download them making the installer
crash.

With this change we hope to significally reduce the chance to have a
failure when running the installer.
The `puma.service` file included here is an adaptation of the ERB
template provided by the capistrano3-puma gem. In order to transition
smoothly from the systemd configuration generated by this installer to
the systemd configuration provided by capistrano3-puma, the
`puma_service_unit_name` must be the same during both installation and
deployment.

Note that, now that Puma starts with systemd, we have to wait till it
creates a socket before continuing; otherwise the socket file won't be
there when we execute the next command, and that command will file.

Also note we have to configure the XDG_RUNTIME_DIR variable. Quoting the
ansible documentation [1]:

> For systemd to work with ‘user’, the executing user must have its own
> instance of dbus started and accessible (systemd requirement).
>
> The user dbus process is normally started during normal login, but not
> during the run of Ansible tasks. Otherwise you will probably get a
> 'Failed to connect to bus: no such file or directory' error.
>
> The user must have access, normally given via setting the
> XDG_RUNTIME_DIR variable.

We also need to check for systemd access because ansible doesn't do it
automatically [2]. In order to allow unprivileged users to enable
lingering to enable systemd user units, we need to install the
policykit-1 package, which is installed by default in Ubuntu but not on
Debian Bookworm. Without this package the action of lingering requires
sudo priveleges.

Finally, we're using Consul Democracy's `master` branch, since it
contains support for Puma with Systemd.

[1] https://docs.ansible.com/ansible/latest/collections/ansible/builtin/systemd_service_module.html#parameter-scope
[2] See issue in 72674 https://github.com/ansible/ansible/issues/

Co-Authored-By: Senén Rodero <[email protected]>
While this isn't needed when starting the Puma service on the server or
with Capistrano, we need the RVM script while using the installer.

The file is now different from the one generated by capistrano3-puma,
but that's alright because it will be overwritten when deploying with
Capistrano (as long as the `:puma_service_unit_name` is the same).
The Docker images for Debian don't include systemd and, even when using
an image that comes with support with systemd [1], we're getting a
warning when starting Puma (the following error takes place when we skip
the "Enable systemd access" step, since that step also raises an error
in Debian):

> Warning: : daemon-reload failed, but target is a chroot or systemd
> is offline.
> Continuing. Error was: 1 / Failed to connect to bus: No such file or
> directory
> Warning: : Target is a chroot or systemd is offline. This can
> lead to false positives or prevent the init system tools from working.

So Puma isn't started in this case.

So now Debian support is uncertain, since we aren't able to test that
Puma starts correctly and the web is accessible. We're at least testing
that the rest of the installation process runs correctly.

[1] https://github.com/trfore/docker-debian11-systemd/blob/main/Dockerfile
1. Errbit does not have the mongodb package available via apt.
2. The latest Errbit version uses ruby 2.7.4 which needs SSL1 while Ubuntu 22.04 supports SSL3.
For some reason I do not know yet, when running the installer on a
Ubuntu 22.04 server it creates the deploy_user home directory with 750 permissions instead of 755.

We need 755 permissions so other users like `www-data`, which runs the nginx service can read from the Consul Democracy puma socket. Otherwise we get a 502 Bad Gateway error when accessing the application.
Since Bookworm comes with PostgreSQL 15, we need to make the
`deploy_user` the database owner. Quoting the PostgreSQL 15 release
notes [1]:

> PostgreSQL 15 also revokes the CREATE permission from all users
> except a database owner from the public (or default) schema.

Now, we first create the user without any privileges, then create the
database with the new user as the database owner and finally grant
all privileges to the new user on the new database.

[1] https://www.postgresql.org/about/news/postgresql-15-released-2526/

Co-Authored-By: Senén Rodero <[email protected]>
@javierm javierm marked this pull request as ready for review February 20, 2024 19:50
@javierm javierm merged commit 23ad31f into master Feb 20, 2024
8 checks passed
@javierm javierm deleted the release_2.1.0 branch February 20, 2024 19:53
@javierm javierm removed the 2.1 label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants