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

Refs #29144 - Use systemd socket activation #814

Merged
merged 1 commit into from
Mar 25, 2020

Conversation

ekohl
Copy link
Member

@ekohl ekohl commented Mar 20, 2020

When using systemd socket activation, it's important that the ListenSocket matches what Puma binds on. Otherwise it may fail. This happens when is configured on [::]:3000 (dual stack) and Puma on 0.0.0.0:3000. Puma will then attempt to bind and fail because the port is already in use.

The service bind is now made explicit because systemd's ListenSocket=3000 binds on :: where Puma by default binds on 0.0.0.0:3000. This is IPv4-only, but is what was done prior to this as well. Apache is configured dual stack and the recommended deployment.

Note this depends on theforeman/foreman#7536 and theforeman/foreman-packaging#4894 (deb) / theforeman/foreman-packaging#4895 (rpm).

manifests/config.pp Outdated Show resolved Hide resolved
}

systemd::dropin_file { 'foreman-service':
filename => 'installer.conf',
Copy link
Member

Choose a reason for hiding this comment

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

Was curious why we call this installer.conf ?

Copy link
Member Author

Choose a reason for hiding this comment

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

We already did this before, but since you can't define systemd::dropin_file twice with 'installer.conf' I had to be explicit. This creates /etc/systemd/system/foreman.service.d/installer.conf and I thought this was the most logical name for it. systemctl cat foreman shows you how it would look like:

# /usr/lib/systemd/system/foreman.service
[Unit]
Description=Foreman
Documentation=https://theforeman.org
After=network.target remote-fs.target nss-lookup.target
Requires=foreman.socket

[Service]
Type=simple
User=foreman
TimeoutSec=300
WorkingDirectory=/usr/share/foreman
ExecStart=/usr/share/foreman/bin/rails server --environment $FOREMAN_ENV --port $FOREMAN_PORT --binding $FOREMAN_BIND
Environment=FOREMAN_ENV=production FOREMAN_PORT=3000 FOREMAN_BIND=0.0.0.0

SyslogIdentifier=foreman

[Install]
WantedBy=multi-user.target

# /etc/systemd/system/foreman.service.d/installer.conf
[Service]
User=foreman
Environment=FOREMAN_ENV=production
Environment=FOREMAN_HOME=/usr/share/foreman
Environment=FOREMAN_BIND=127.0.0.1
Environment=FOREMAN_PORT=3000
Environment=FOREMAN_PUMA_THREADS_MIN=0
Environment=FOREMAN_PUMA_THREADS_MAX=16
Environment=FOREMAN_PUMA_WORKERS=2

@ekohl ekohl force-pushed the 29144-systemd-socket-activation branch from 92fe8e5 to 6e2cc5e Compare March 20, 2020 18:13
@ekohl
Copy link
Member Author

ekohl commented Mar 20, 2020

I've updated it to reuse $listen_socket in the Apache reverse proxy config. This makes it even clearer that these are directly linked. In a later iteration we can have a look at using unix sockets which can prevent attacks (currently anyone on the local host can send HTTP(S) headers impersonating hosts)

@ehelms
Copy link
Member

ehelms commented Mar 24, 2020

Looks like a linting error

@ekohl
Copy link
Member Author

ekohl commented Mar 24, 2020

voxpupuli/puppet-lint-unquoted_string-check#4 is the lint issue.

@ehelms
Copy link
Member

ehelms commented Mar 25, 2020

Hrmm, can we work around it for now?

@ekohl
Copy link
Member Author

ekohl commented Mar 25, 2020

voxpupuli/puppet-lint-unquoted_string-check#9 is the bugfix. Working on releasing a fix for it.

@ekohl
Copy link
Member Author

ekohl commented Mar 25, 2020

Restarted the failed tests now that the new version is out.

@mmoll
Copy link
Contributor

mmoll commented Mar 25, 2020

tests fail 💔

When using systemd socket activation, it's important that the
ListenSocket matches what Puma binds on. Otherwise it may fail. This
happens when is configured on [::]:3000 (dual stack) and Puma on
0.0.0.0:3000. Puma will then attempt to bind and fail because the port
is already in use.

The service bind is now made explicit because systemd's
ListenSocket=3000 binds on :: where Puma by default binds on
0.0.0.0:3000. This is IPv4-only, but is what was done prior to this as
well. Apache is configured dual stack and the recommended deployment.
@ekohl ekohl force-pushed the 29144-systemd-socket-activation branch from 6e2cc5e to 281f196 Compare March 25, 2020 17:09
@ekohl
Copy link
Member Author

ekohl commented Mar 25, 2020

I wonder why https://travis-ci.org/github/theforeman/puppet-foreman/builds/666888226 is not in the status checks

@ehelms
Copy link
Member

ehelms commented Mar 25, 2020

Seems Travis might be having a rough time

@ekohl
Copy link
Member Author

ekohl commented Mar 25, 2020

💚 now

@ekohl ekohl merged commit 281f196 into theforeman:master Mar 25, 2020
@ekohl ekohl deleted the 29144-systemd-socket-activation branch March 25, 2020 18:01
@ekohl
Copy link
Member Author

ekohl commented Mar 26, 2020

I'm not entirely sure if this is breaking or not. I think it still works on Foreman 2.0 since we don't manage foreman.socket. However, perhaps we need to. Labeled as enhancement for now.

sthirugn added a commit to sthirugn/foreman-installer that referenced this pull request Apr 1, 2020
The commit bd02fbd reverted commit 0b244f5.

theforeman/puppet-foreman#814 fixed the race
condition of systemctl start foreman returning immediately before the
service was up.
sthirugn added a commit to sthirugn/foreman-installer that referenced this pull request Apr 1, 2020
The commit bd02fbd reverted commit 0b244f5.

theforeman/puppet-foreman#814 fixed the race
condition of systemctl start foreman returning immediately before the
service was up.
sthirugn added a commit to sthirugn/foreman-installer that referenced this pull request Apr 2, 2020
The commit bd02fbd reverted commit 0b244f5.

theforeman/puppet-foreman#814 fixed the race
condition of systemctl start foreman returning immediately before the
service was up.
ekohl pushed a commit to theforeman/foreman-installer that referenced this pull request Apr 2, 2020
The commit bd02fbd reverted commit 0b244f5.

theforeman/puppet-foreman#814 fixed the race
condition of systemctl start foreman returning immediately before the
service was up.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants