Skip to content

Fix service status detection on Debian-based OSes #1349

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
Jul 12, 2022

Conversation

arjenz
Copy link
Contributor

@arjenz arjenz commented Jul 4, 2022

/usr/sbin/service postgresql@*-main status on at least Ubuntu 18.04, 20.04 and 22.04, always exits 0 (even when service is down), so puppet always believes the service is up (which both causes all kinds of failures and prevents puppet from starting the stopped service).

Not sure why all the convoluted logic in this bit is needed, but this fixes it for me on 18 and 20 (and also 22 but that's not yet supported by this module).

@arjenz arjenz requested a review from a team as a code owner July 4, 2022 09:40
@puppet-community-rangefinder
Copy link

postgresql::params is a class

Breaking changes to this file WILL impact these 2 modules (exact match):
Breaking changes to this file MAY impact these 3 modules (near match):

This module is declared in 70 of 579 indexed public Puppetfiles.


These results were generated with Rangefinder, a tool that helps predict the downstream impact of breaking changes to elements used in Puppet modules. You can run this on the command line to get a full report.

Exact matches are those that we can positively identify via namespace and the declaring modules' metadata. Non-namespaced items, such as Puppet 3.x functions, will always be reported as near matches only.

Copy link
Collaborator

@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.

Would a similar fix work for Debian? Perhaps then all the logic to determine $service_status can be made trivial. In fact, isn't this the default implementation? So just set it to undef?

You could also copy this for non-systemd support (which Debian still officially has):

if pick($service_provider, $facts['service_provider']) == 'systemd' {
$service_reload = "systemctl reload ${service_name}"
$service_status = "systemctl status ${service_name}"
} else {
$service_reload = "service ${service_name} reload"
$service_status = "service ${service_name} status"
}

Now I also see that RH-based distros don't respect the service_status global parameter, which is a bug in itself.

@arjenz
Copy link
Contributor Author

arjenz commented Jul 4, 2022

I would think it would also work on Debian. After reading all this it wasn't quite clear to me as to why all this logic is there (instead of, as you mentioned, rely on the default, which is working fine) so I didn't dare wiping it, just fixed its behavior for 18 and up.

I'd be all for removing all this :)

@ekohl
Copy link
Collaborator

ekohl commented Jul 4, 2022

Now I also see that RH-based distros don't respect the service_status global parameter, which is a bug in itself.

I opened #1351 for this.

I'd be all for removing all this :)

I'd be in favor of this. @david22swan any thoughts?

ekohl added a commit to ekohl/puppet-foreman that referenced this pull request Jul 4, 2022
This is to test out if
puppetlabs/puppetlabs-postgresql#1349 could fix
our broken Ubuntu 20.04 tests.
@david22swan
Copy link
Member

david22swan commented Jul 4, 2022

@ekohl @arjenz
Looking at it.......
Yeh, it's weird and messy that it's still got code for unsupported versions.
I'd be fine with it getting removed and something along the lines of the RHEL family implementation of it getting put in its place as Ekohl suggested.

@arjenz
Copy link
Contributor Author

arjenz commented Jul 11, 2022

@ekohl @david22swan I rewrote it to match the bits @ekohl added for RHEL, tested (successfully) it on Debian 10/11, Ubuntu {18,20,22}.04. I think people who rely on other service tooling than service or systemctl can just set it as a parameter.

Copy link
Collaborator

@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.

It looks like the unit tests need to be modified to reflect these changes, otherwise 👍

Copy link
Collaborator

@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.

I think the suse acceptance test failures are unrelated. I can't see how they would be affected, but I don't know suse either.

Copy link
Collaborator

@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.

Apologies, I missed the test failures.

Comment on lines -172 to +174
} elsif $facts['os']['name'] == 'Ubuntu' and versioncmp($facts['os']['release']['major'], '18.04') >= 0 {
$service_status = pick($service_status, "/usr/sbin/service ${service_name}@*-main status")
} elsif $facts['os']['name'] == 'Ubuntu' and versioncmp($facts['os']['release']['major'], '15.04') >= 0 {
# Ubuntu releases since vivid use systemd
$service_status = pick($service_status, "/usr/sbin/service ${service_name} status")
if pick($service_provider, $facts['service_provider']) == 'systemd' {
$service_reload = "systemctl reload ${service_name}"
$service_status = pick($service_status, "systemctl status ${service_name}")
} else {
$service_status = pick($service_status, "/etc/init.d/${service_name} status | /bin/egrep -q 'Running clusters: .+|online'")
$service_reload = "service ${service_name} reload"
$service_status = pick($service_status, "service ${service_name} status")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, I think these paths need to be absolute.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah, I cheated a bit, as it moved from /bin/ to /usr/bin/ or the other way around, but I think both work anyway (as does omitting the path, but I agree, having full path is better :) ).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh disregard that, I copy/pasted this bit, throughout that file the commands are used without absolute path. I think we could/should change that, but I think now local style is "without full path"

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd be OK with that (I've seen that Puppet does apply $PATH to it, unlike exec), but then the unit tests should match.

ekohl
ekohl previously approved these changes Jul 12, 2022
Copy link
Collaborator

@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.

Waiting for CI to complete

Copy link
Collaborator

@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.

Thanks! I think SLES is unrelated but I can't tell because https://github.com/puppetlabs/puppetlabs-postgresql/actions/runs/2653307902 excluded SLES.

@ekohl ekohl changed the title Fix service status detection Fix service status detection on Debian-based OSes Jul 12, 2022
@ekohl ekohl added the feature label Jul 12, 2022
@ekohl ekohl merged commit 309dc76 into puppetlabs:main Jul 12, 2022
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