Add the option to wait for another service/s before starting (systemd only)

Issue: PROD-18135
Change-Id: I88f56bc501d868bb99b6481e5a65adb701fe538e
diff --git a/README.rst b/README.rst
index 6c50317..a920e2d 100644
--- a/README.rst
+++ b/README.rst
@@ -469,6 +469,18 @@
               name: 127.0.0.1
               port: 8888
 
+Nginx configured to wait for another service/s before starting (currently only with systemd)
+
+.. code-block:: yaml
+
+    nginx:
+      server:
+        wait_for_service:
+          - foo-bar.mount
+        enabled: true
+        site:
+          ...
+
 More Information
 ================
 
diff --git a/nginx/files/service.override.conf b/nginx/files/service.override.conf
new file mode 100644
index 0000000..b861ffa
--- /dev/null
+++ b/nginx/files/service.override.conf
@@ -0,0 +1,5 @@
+{%- from "nginx/map.jinja" import server with context -%}
+[Unit]
+{%- for service in server.wait_for_service %}
+After={{ service }}
+{%- endfor %}
diff --git a/nginx/server.sls b/nginx/server.sls
index 222f06c..4cfd577 100644
--- a/nginx/server.sls
+++ b/nginx/server.sls
@@ -97,4 +97,35 @@
     - service: nginx_service
 {%- endif %}
 
+{%- if server.wait_for_service is defined %}
+
+{%- if salt['test.provider']('service') == 'systemd' %}
+
+/etc/systemd/system/nginx.service.d:
+  file.directory:
+  - mode: 0755
+  - user: root
+  - group: root
+  - require:
+    - pkg: nginx_packages
+
+/etc/systemd/system/nginx.service.d/override.conf:
+  file.managed:
+  - source: salt://nginx/files/service.override.conf
+  - template: jinja
+  - require:
+    - file: /etc/systemd/system/nginx.service.d
+
+systemctl_reload:
+  module.run:
+  - name: service.systemctl_reload
+  - onchanges:
+    - file: /etc/systemd/system/nginx.service.d/override.conf
+  - watch_in:
+    - service: nginx_service
+
+{%- endif %}
+
+{%- endif %}
+
 {%- endif %}