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

fixes #19480 - add systemd notify support #525

Merged
merged 1 commit into from May 9, 2017

Conversation

domcleal
Copy link
Contributor

@domcleal domcleal commented May 9, 2017

When started under systemd, the launcher now logs via the notify socket
API when all configured WEBrick servers have started so the service
state is reported accurately (rather than the daemonization point).

An example unit file is now shipped that uses a --no-daemonize
argument to override the config file, so misconfiguration will not
prevent the service from starting correctly.

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

Looks very good.

Type=notify
User=foreman-proxy
ExecStart=/usr/share/foreman-proxy/bin/smart-proxy --no-daemonize
EnvironmentFile=-/etc/sysconfig/foreman-proxy
Copy link
Member

Choose a reason for hiding this comment

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

This is RH specific. Debian has /etc/default but I'm wondering if the environment is even used. If users need it they can override it in /etc/systemd/system/foreman-proxy.service.d/override.conf.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I had been thinking that packages for other OSes could patch the location, but preferring the systemd overrides seems a much better default. This can be added back in for RPM packages for their backwards-compatibility. Line removed.

end

def notify(message)
socket.sendmsg(message.chomp + "\n") # ensure trailing \n
Copy link
Member

Choose a reason for hiding this comment

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

You aren't closing the socket when you are done with it. Or is this intentional so other changes in state (restarts, for example) can be passed to systemd?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was relying on the GC to finalise the object, which would autoclose it. I've changed it to explicitly close the socket as soon as it's done to free up the fd.

@@ -43,6 +43,7 @@

module Proxy
SETTINGS = Settings.load_global_settings
SETTINGS.apply_argv(ARGV)
Copy link
Member

Choose a reason for hiding this comment

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

More of a nitpick: I think Settings::Global#apply_argv call could be made from Settings.load_global_settings, mostly to keep settings initialization logic in one spot. If so, Settings.load_global_settings should probably be renamed to something like Settings.initialize_global_settings...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, updated as suggested.


class SdNotifyTest < Test::Unit::TestCase
def test_active_with_notify_socket
with_notify_socket('/run/systemd/notify') do
Copy link
Member

Choose a reason for hiding this comment

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

Any reason you are using an actual systemd socket instead of a temporary one here?

Copy link
Contributor Author

@domcleal domcleal May 9, 2017

Choose a reason for hiding this comment

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

It's actually a mocked environment variable, just set to a real life path. I've changed it to /mock to make this clearer.

Copy link
Member

Choose a reason for hiding this comment

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

Ahh, yes, Proxy::SdNotify.new.active? only checks that the environment variable isn't nil. The change made it clear(er) though, thanks.

When started under systemd, the launcher now logs via the notify socket
API when all configured WEBrick servers have started so the service
state is reported accurately (rather than the daemonization point).

An example unit file is now shipped that uses a --no-daemonize
argument to override the config file, so misconfiguration will not
prevent the service from starting correctly.
@domcleal
Copy link
Contributor Author

domcleal commented May 9, 2017

PR updated, thanks for the reviews.

@dmitri-d dmitri-d merged commit 99e9e5b into theforeman:develop May 9, 2017
@dmitri-d
Copy link
Member

dmitri-d commented May 9, 2017

Merged, thanks @domcleal!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants