-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
homebrew: Add support for services functions #8329
base: main
Are you sure you want to change the base?
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution! Here are some first comments.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Hi @felixfontein, who should I put as the author for this? I'm happy to be a maintainer if that's expected of me. Otherwise if existing authors for the homebrew.py package makes more sense, happy to do that do. |
Since you created it, I would put yourself in there :) Depending on how much you copied over from the existing module, adding the author(s) from the original module also makes sense. (If you used code from existing modules, it's best to copy over their copyright lines so it's clear that you didn't create everything yourself. Adding the authors of the other module as authors is optional, but the copyright lines are not.) If you add a new module or plugin we expect you to at least maintain it for some time, so you'd also need to add yourself to BOTMETA (see https://github.com/ansible-collections/community.general/blob/main/CONTRIBUTING.md#creating-new-modules-or-plugins for details). |
plugins/modules/homebrew_services.py
Outdated
name: | ||
description: | ||
- An installed homebrew package whose service is to be updated. | ||
aliases: [ 'formula', 'package', 'pkg' ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general adding aliases should be avoided in not necessary. I can see why formula
makes sense, but are package
and pkg
really needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mainly matching the aliases in the other homebrew modules for consistency. But if these are unorthodox, I'm happy to nix them.
Yup! Makes sense. Only too happy to. |
Fixes ansible-collections#8286. Add a homebrew.services module for starting and stopping services that are attached to homebrew packages.
Hmmm, not sure what to make of the following error:
There seem to be multiple errors. One about getcwd permissions and one error parsing the JSON output of the services call. But I can't reproduce those on my system. Is there some extra stuff I need to set up for permissions in the Mac tests for CI? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The complete stderr in readable form is:
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
Traceback (most recent call last):
File "<stdin>", line 133, in <module>
File "<stdin>", line 125, in _ansiballz_main
File "<stdin>", line 73, in invoke_module
File "<frozen runpy>", line 226, in run_module
File "<frozen runpy>", line 98, in _run_module_code
File "<frozen runpy>", line 88, in _run_code
File "/tmp/ansible_community.general.homebrew_services_payload_eupguqp0/ansible_community.general.homebrew_services_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_services.py", line 279, in <module>
File "/tmp/ansible_community.general.homebrew_services_payload_eupguqp0/ansible_community.general.homebrew_services_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_services.py", line 264, in main
File "/tmp/ansible_community.general.homebrew_services_payload_eupguqp0/ansible_community.general.homebrew_services_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_services.py", line 183, in start_service
File "/tmp/ansible_community.general.homebrew_services_payload_eupguqp0/ansible_community.general.homebrew_services_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_services.py", line 150, in _brew_service_state
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
My guess is that
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
are warnings printed by brew services info black --json
, and it didn't output JSON on stdout.
I would probably add a command
task to the tests before Start the black service
that simply runs brew services info black --json
. Then maybe it's easier to see what's going wrong? I've added it below as a suggestion and will commit it.
While it doesn't show where the messages on stderr come from, it shows why stdout isn't JSON: it starts with two non-JSON lines
(And seriously, dumping stuff on stdout when the user is explicitly asking for JSON is a really bad idea.) It also shows that you should use better error handling and not simply assume that stdout is JSON :) |
SUMMARY
Add a homebrew.services module for starting and stopping services that are attached to homebrew packages.
Fixes #8286.
ISSUE TYPE
COMPONENT NAME
homebrew, homebrew_services
ADDITIONAL INFORMATION
Can now make sure a homebrew service is running with: