Skip to content

Add options for failing resource check on command line #9257

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

Conversation

cthorn42
Copy link
Collaborator

@cthorn42 cthorn42 commented Feb 20, 2024

When running puppet resource service, and the service does not exist, the application will return a 0 exit code and display that the service is not running.
This PR introduces a new option for the puppet resource service application, --fail, if the service is not found and the option is used, the application will return with a non-zero exit code, and display an error message.
Example of use:

[root@potent-image ~]# puppet resource service made_up_service ensure=running --fail
Error: Systemd start for made_up_service failed!
journalctl log for made_up_service:
-- No entries --

Error: /Service[made_up_service]/ensure: change from 'absent' to 'running' failed: Systemd start for made_up_service failed!
journalctl log for made_up_service:
-- No entries --

Error: Could not run: Failed to manage resource Service[made_up_service]
[root@potent-image ~]# echo $?
1

Here is an example without the flag:

[root@potent-image ~]# puppet resource service made_up_service ensure=running
Error: Systemd start for made_up_service failed!
journalctl log for made_up_service:
-- No entries --

Error: /Service[made_up_service]/ensure: change from 'absent' to 'running' failed: Systemd start for made_up_service failed!
journalctl log for made_up_service:
-- No entries --
[root@potent-image ~]# echo $?
0

@joshcooper
Copy link
Contributor

LGTM, could you squash the last two commits? Something like this should do the trick

git reset HEAD^
git add lib/puppet/application/resource.rb
git commit --amend
git push -f origin HEAD

@cthorn42 cthorn42 force-pushed the maint/main/systemd_resource_not_found_error branch from 8685a72 to 1a9c299 Compare February 21, 2024 00:32
@cthorn42 cthorn42 force-pushed the maint/main/systemd_resource_not_found_error branch from 1a9c299 to 7fc2806 Compare February 22, 2024 17:24
@cthorn42 cthorn42 force-pushed the maint/main/systemd_resource_not_found_error branch from 7fc2806 to 248dbe5 Compare February 27, 2024 19:09
@joshcooper joshcooper changed the title Maint/main/resource not found error Add options for failing resource check on command line Feb 28, 2024
@joshcooper joshcooper merged commit 29ffbfc into puppetlabs:main Feb 28, 2024
@joshcooper joshcooper added the enhancement New feature or request label Feb 28, 2024
cthorn42 added a commit to cthorn42/puppet that referenced this pull request Mar 6, 2024
…ystemd_resource_not_found_error"

This reverts commit 29ffbfc, reversing
changes made to 57a00cc.
joshcooper added a commit that referenced this pull request Mar 6, 2024
…urce_service_change

Revert "Merge pull request #9257 from cthorn42/maint/main/systemd_res…
alanhargreaves pushed a commit to alanhargreaves/puppet that referenced this pull request Mar 18, 2024
…ystemd_resource_not_found_error"

This reverts commit 29ffbfc, reversing
changes made to 57a00cc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants