apache-formula icon indicating copy to clipboard operation
apache-formula copied to clipboard

fix(apache.service.running): prevent recursive requisite

Open alxwr opened this issue 1 year ago • 3 comments

PR progress checklist (to be filled in by reviewers)

  • [ ] Changes to documentation are appropriate (or tick if not required)
  • [ ] Changes to tests are appropriate (or tick if not required)
  • [ ] Reviews completed

What type of PR is this?

Primary type

  • [ ] [build] Changes related to the build system
  • [ ] [chore] Changes to the build process or auxiliary tools and libraries such as documentation generation
  • [ ] [ci] Changes to the continuous integration configuration
  • [ ] [feat] A new feature
  • [x] [fix] A bug fix
  • [ ] [perf] A code change that improves performance
  • [ ] [refactor] A code change that neither fixes a bug nor adds a feature
  • [ ] [revert] A change used to revert a previous commit
  • [ ] [style] Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.)

Secondary type

  • [ ] [docs] Documentation changes
  • [ ] [test] Adding missing or correcting existing tests

Does this PR introduce a BREAKING CHANGE?

No.

Related issues and/or pull requests

Describe the changes you're proposing

I made this error go away: :-)

% salt --state-output=changes --state-verbose=False 'host.test' state.apply apache.config.file test=True
host.test:
----------
          ID: apache-service-running
    Function: service.running
        Name: apache2
      Result: False
     Comment: Recursive requisite found
     Changes:
[...]
----------
          ID: apache-service-running-restart
    Function: module.wait
        Name: service.restart
      Result: False
     Comment: Recursive requisite found
     Changes:   
----------
          ID: apache-service-running-reload
    Function: module.wait
        Name: service.reload
      Result: False
     Comment: Recursive requisite found
     Changes:

Pillar / config required to test the proposed changes

Debug log showing how the proposed changes work

% salt --state-output=changes --state-verbose=False 'host.test' state.apply apache.config.file test=True
host.test:
----------
          ID: apache-service-running
    Function: service.running
        Name: apache2
      Result: None
     Comment: Service apache2 is set to start  The state would be retried every 10 seconds (with a splay of up to 10 seconds) a maximum of 2 times or until a result of True is returned
     Started: 21:51:08.152014
    Duration: 12.319 ms
     Changes:   
----------
          ID: apache-service-running
    Function: cmd.run
        Name: journalctl -xe -u apache2 || tail -20 /var/log/messages || true
      Result: None
     Comment: Command "journalctl -xe -u apache2 || tail -20 /var/log/messages || true" would have been executed
     Started: 21:51:08.164573
    Duration: 0.464 ms
     Changes:   
              ----------
              cmd:
                  journalctl -xe -u apache2 || tail -20 /var/log/messages || true
----------
          ID: apache-service-running
    Function: cmd.run
        Name: (service apache2 restart && service apache2 status) || true
      Result: None
     Comment: Command "(service apache2 restart && service apache2 status) || true" would have been executed
     Started: 21:51:08.165158
    Duration: 0.414 ms
     Changes:   
              ----------
              cmd:
                  (service apache2 restart && service apache2 status) || true
----------
          ID: apache-service-running
    Function: cmd.run
        Name: cat /etc/apache2/apache2.conf
      Result: None
     Comment: Command "cat /etc/apache2/apache2.conf" would have been executed
     Started: 21:51:08.165693
    Duration: 0.417 ms
     Changes:   
              ----------
              cmd:
                  cat /etc/apache2/apache2.conf

Summary for host.test
-------------
Succeeded: 20 (unchanged=4, changed=3)
Failed:     0
-------------
Total states run:     20
Total run time:  110.024 ms

Documentation checklist

  • [ ] Updated the README (e.g. Available states).
  • [ ] Updated pillar.example.

Testing checklist

  • [ ] Included in Kitchen (i.e. under state_top).
  • [ ] Covered by new/existing tests (e.g. InSpec, Serverspec, etc.).
  • [ ] Updated the relevant test pillar.

Additional context

alxwr avatar Mar 21 '24 21:03 alxwr

Had this problem and these changes actually made it work properly.

MartinZbozien avatar Apr 04 '24 13:04 MartinZbozien

Had the problem as well, this fixed it mostly. I only had to add the following change to remove the "Recursive requisite found" message for the configure modules:

diff --git a/formulas/apache/config/modules/install.sls b/formulas/apache/config/modules/install.sls
index 5bab8295..c7f4fecf 100644
--- a/formulas/apache/config/modules/install.sls
+++ b/formulas/apache/config/modules/install.sls
@@ -40,8 +40,6 @@ apache-config-modules-{{ module }}-enable:
 
         {%- endif %}
     - order: 225
-    - require:
-      - sls: {{ sls_config_file }}
     - watch_in:
       - module: apache-service-running-restart
     - require_in:

danny-smit avatar Apr 17 '24 10:04 danny-smit

Small update to my previous comment.

The state in apache/config/modules/install.sls contains a hard order: 225, which would order it before all other states without an order key. This can give problems on new installed machines. Instead, the following change should fix both the "Recursive requisite" and the ordering issue:

diff --git a/apache/config/modules/install.sls b/apache/config/modules/install.sls
index 9cc5273..b85c80c 100644
--- a/apache/config/modules/install.sls
+++ b/apache/config/modules/install.sls
@@ -41,7 +41,7 @@ apache-config-modules-{{ module }}-enable:
         {%- endif %}
     - order: 225
     - require:
-      - sls: {{ sls_config_file }}
+      - file: apache-config-file-directory-moddir
     - watch_in:
       - module: apache-service-running-restart
     - require_in:

danny-smit avatar Apr 18 '24 11:04 danny-smit