saltstack / saltstack/salt

Service state for PostgreSQL installed by brew doesn't work on macOS

Open
#63,020 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug MacOS needs-triage
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

Description of Issue

I'm trying to install Postgres from brew and confirm the Postgres service is running. I have been unable to do so using different approaches.

Bumping the service manually with brew does work:
brew services restart postgresql@14
==> Successfully started postgresql@14 (label: homebrew.mxcl.postgresql@14)

I also tried to pass runas: with the local user, but that didn't help.

Setup
install postgres:
  pkg.installed:
    - name: postgresql@14

  service.running:
    - name: postgresql@14
    - enable: True
Steps to Reproduce Issue

sudo salt-call --local state.apply

[ERROR   ] The named service postgresql@14 is not available
local:
----------
          ID: install postgres
    Function: pkg.installed
        Name: postgresql@14
      Result: True
     Comment: The following packages were installed/updated: postgresql@14
     Started: 14:03:13.428801
    Duration: 84852.408 ms
     Changes:
              ----------
              postgresql@14:
                  ----------
                  new:
                      14.5_5
                  old:
----------
          ID: install postgres
    Function: service.running
        Name: postgresql@14
      Result: False
     Comment: The named service postgresql@14 is not available
     Started: 14:04:38.288075
    Duration: 1662.306 ms
     Changes:

Summary for local
------------
Succeeded: 1 (changed=1)
Failed:    1
------------
Total states run:     2
Total run time:  86.515 s

I then tried something more involved:

install postgres:
  pkg.installed:
    - name: postgresql@14

  file.managed:
    - name: /Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist
    - source: /usr/local/opt/postgresql@14/homebrew.mxcl.postgresql@14.plist
    - group: wheel

postgresql-running:
  service.running:
    - name: homebrew.mxcl.postgresql@14
    - enable: True
[ERROR   ] An exception occurred in this state: Traceback (most recent call last):
  File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/state.py", line 2276, in call
    ret = self.states[cdata["full"]](
  File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/loader/lazy.py", line 149, in __call__
    return self.loader.run(run_func, *args, **kwargs)
  File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/loader/lazy.py", line 1228, in run
    return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
  File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/loader/lazy.py", line 1243, in _run_as
    return _func_or_method(*args, **kwargs)
  File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/loader/lazy.py", line 1276, in wrapper
    return f(*args, **kwargs)
  File "/opt/salt/.pyenv/versions/3.9.12/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/states/service.py", line 485, in running
    before_toggle_status = __salt__["service.status"](name, sig, **status_kwargs)
  File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/loader/lazy.py", line 149, in __call__
    return self.loader.run(run_func, *args, **kwargs)
  File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/loader/lazy.py", line 1228, in run
    return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
  File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/loader/lazy.py", line 1243, in _run_as
    return _func_or_method(*args, **kwargs)
  File "/opt/salt/.pyenv/versions/3.9.12/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/modules/mac_service.py", line 528, in status
    output = __salt__["service.list"](name, runas=runas)
  File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/loader/lazy.py", line 149, in __call__
    return self.loader.run(run_func, *args, **kwargs)
  File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/loader/lazy.py", line 1228, in run
    return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
  File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/loader/lazy.py", line 1243, in _run_as
    return _func_or_method(*args, **kwargs)
  File "/opt/salt/.pyenv/versions/3.9.12/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/modules/mac_service.py", line 351, in list_
    return launchctl("list", label, return_stdout=True, runas=runas)
  File "/opt/salt/.pyenv/versions/3.9.12/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/modules/mac_service.py", line 318, in launchctl
    return __utils__["mac_utils.launchctl"](sub_cmd, *args, **kwargs)
  File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/loader/lazy.py", line 149, in __call__
    return self.loader.run(run_func, *args, **kwargs)
  File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/loader/lazy.py", line 1228, in run
    return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
  File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/loader/lazy.py", line 1243, in _run_as
    return _func_or_method(*args, **kwargs)
  File "/opt/salt/.pyenv/versions/3.9.12/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/utils/mac_utils.py", line 311, in launchctl
    ret = __salt__["cmd.run_all"](cmd, **kwargs)
  File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/modules/cmdmod.py", line 994, in _run_all_quiet
    return _run(
  File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/modules/cmdmod.py", line 447, in _run
    user_shell = __salt__["user.info"](runas)["shell"]
NameError: name '__salt__' is not defined

local:
----------
          ID: install postgres
    Function: pkg.installed
        Name: postgresql@14
      Result: True
     Comment: The following packages were installed/updated: postgresql@14
     Started: 14:06:30.178110
    Duration: 77223.374 ms
     Changes:
              ----------
              postgresql@14:
                  ----------
                  new:
                      14.5_5
                  old:
----------
          ID: install postgres
    Function: file.managed
        Name: /Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist
      Result: True
     Comment: File /Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist updated
     Started: 14:07:47.407093
    Duration: 5.766 ms
     Changes:
              ----------
              diff:
                  New file
              mode:
                  0644
----------
          ID: postgresql-running
    Function: service.running
        Name: homebrew.mxcl.postgresql@14
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/state.py", line 2276, in call
                  ret = self.states[cdata["full"]](
                File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/loader/lazy.py", line 149, in __call__
                  return self.loader.run(run_func, *args, **kwargs)
                File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/loader/lazy.py", line 1228, in run
                  return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
                File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/loader/lazy.py", line 1243, in _run_as
                  return _func_or_method(*args, **kwargs)
                File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/loader/lazy.py", line 1276, in wrapper
                  return f(*args, **kwargs)
                File "/opt/salt/.pyenv/versions/3.9.12/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/states/service.py", line 485, in running
                  before_toggle_status = __salt__["service.status"](name, sig, **status_kwargs)
                File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/loader/lazy.py", line 149, in __call__
                  return self.loader.run(run_func, *args, **kwargs)
                File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/loader/lazy.py", line 1228, in run
                  return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
                File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/loader/lazy.py", line 1243, in _run_as
                  return _func_or_method(*args, **kwargs)
                File "/opt/salt/.pyenv/versions/3.9.12/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/modules/mac_service.py", line 528, in status
                  output = __salt__["service.list"](name, runas=runas)
                File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/loader/lazy.py", line 149, in __call__
                  return self.loader.run(run_func, *args, **kwargs)
                File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/loader/lazy.py", line 1228, in run
                  return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
                File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/loader/lazy.py", line 1243, in _run_as
                  return _func_or_method(*args, **kwargs)
                File "/opt/salt/.pyenv/versions/3.9.12/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/modules/mac_service.py", line 351, in list_
                  return launchctl("list", label, return_stdout=True, runas=runas)
                File "/opt/salt/.pyenv/versions/3.9.12/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/modules/mac_service.py", line 318, in launchctl
                  return __utils__["mac_utils.launchctl"](sub_cmd, *args, **kwargs)
                File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/loader/lazy.py", line 149, in __call__
                  return self.loader.run(run_func, *args, **kwargs)
                File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/loader/lazy.py", line 1228, in run
                  return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
                File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/loader/lazy.py", line 1243, in _run_as
                  return _func_or_method(*args, **kwargs)
                File "/opt/salt/.pyenv/versions/3.9.12/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/utils/mac_utils.py", line 311, in launchctl
                  ret = __salt__["cmd.run_all"](cmd, **kwargs)
                File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/modules/cmdmod.py", line 994, in _run_all_quiet
                  return _run(
                File "/opt/salt/lib/python3.9/site-packages/salt-3005.1-py3.9.egg/salt/modules/cmdmod.py", line 447, in _run
                  user_shell = __salt__["user.info"](runas)["shell"]
              NameError: name '__salt__' is not defined
     Started: 14:07:47.417782
    Duration: 1274.669 ms
     Changes:

Summary for local
------------
Succeeded: 2 (changed=2)
Failed:    1
------------
Total states run:     3
Total run time:  78.504 s
Versions Report

Salt Version:
Salt: 3005.1

Dependency Versions:
cffi: 1.14.6
cherrypy: unknown
dateutil: 2.8.0
docker-py: Not Installed
gitdb: 4.0.5
gitpython: 3.1.12
Jinja2: 3.1.0
libgit2: Not Installed
M2Crypto: Not Installed
Mako: 1.1.4
msgpack: 1.0.2
msgpack-pure: Not Installed
mysql-python: Not Installed
pycparser: 2.21
pycrypto: Not Installed
pycryptodome: 3.9.8
pygit2: Not Installed
Python: 3.9.12 (main, Sep 27 2022, 13:31:44)
python-gnupg: 0.4.8
PyYAML: 5.4.1
PyZMQ: 23.2.0
smmap: 3.0.2
timelib: 0.2.4
Tornado: 4.5.3
ZMQ: 4.3.4

System Versions:
dist: darwin 21.6.0
locale: utf-8
machine: x86_64
release: 21.6.0
system: Darwin
version: 12.6 x86_64

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the macOS service failure with the provided Salt state and PostgreSQL Homebrew service name. Read salt/modules/mac_service.py, especially status(), list_(), and launchctl(), together with salt/utils/mac_utils.py and salt/modules/cmdmod.py; done means the reported service check no longer returns the unavailable-service failure or NameError.

Written by the indexing model from the issue text.

Assessment

Tech stack
macos, python
Domain
devops, infrastructure, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.