saltstack-formulas / apache-formula

Set up and configure the Apache HTTP server
http://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html
Other
50 stars 285 forks source link

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

Open alxwr opened 5 months ago

alxwr commented 5 months ago

PR progress checklist (to be filled in by reviewers)


What type of PR is this?

Primary type

Secondary type

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

Testing checklist

Additional context

MartinZbozien commented 5 months ago

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

danny-smit commented 4 months ago

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 commented 4 months ago

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: