Enable services restart on systemd lvl

  * Those patch enable salt-(minion|master|api) services
    daemon auto-restart, in case any unclear exit will be
    detected. Systemd will try to run service each 3sec,
    till _StartLimitBurst_ limit will not be reached.
    (default 5)
  * Migrate systemd_minion_override.conf file
  * Duplicate patch for minion in base.sls and in service.sls

Change-Id: I65f35f1c50935af5692b740bb75ba0a629b18c48
Closes-Bug: PROD-23969 (PROD:23969)
diff --git a/salt/api.sls b/salt/api.sls
index 2d7ac5a..5afc8f9 100644
--- a/salt/api.sls
+++ b/salt/api.sls
@@ -26,15 +26,29 @@
   - creates: /etc/ssl/certs/{{ api.ssl.get('name', grains.id) }}-chain.crt
   - watch_in:
     - service: salt_api_service
-
 {%- endif %}
 
 salt_api_service:
   service.running:
-  - name: salt-api
+  - name: {{ api.service }}
   - require:
     - pkg: salt_api_packages
   - watch:
     - file: /etc/salt/master.d/_api.conf
 
-{%- endif %}
\ No newline at end of file
+{%- if grains.get('init', None) == 'systemd' %}
+salt_api_systemd_override:
+  file.managed:
+    - name: /etc/systemd/system/{{ api.service }}.service.d/50-restarts.conf
+    - source: salt://salt/files/systemd/{{ api.service }}.service_50-restarts
+    - makedirs: True
+
+salt_api_systemd_reload:
+  module.wait:
+    - name: service.systemctl_reload
+    - onchanges:
+      - file: salt_api_systemd_override
+    - watch_in:
+      - service: salt_api_service
+{%- endif %}
+{%- endif %}
diff --git a/salt/files/systemd/salt-api.service_50-restarts b/salt/files/systemd/salt-api.service_50-restarts
new file mode 100644
index 0000000..5dee5d7
--- /dev/null
+++ b/salt/files/systemd/salt-api.service_50-restarts
@@ -0,0 +1,3 @@
+[Service]
+Restart=always
+RestartSec=3
diff --git a/salt/files/systemd/salt-master.service_50-restarts b/salt/files/systemd/salt-master.service_50-restarts
new file mode 100644
index 0000000..5dee5d7
--- /dev/null
+++ b/salt/files/systemd/salt-master.service_50-restarts
@@ -0,0 +1,3 @@
+[Service]
+Restart=always
+RestartSec=3
diff --git a/salt/files/systemd_minion_override.conf b/salt/files/systemd/salt-minion.service_40-override
similarity index 100%
rename from salt/files/systemd_minion_override.conf
rename to salt/files/systemd/salt-minion.service_40-override
diff --git a/salt/files/systemd/salt-minion.service_50-restarts b/salt/files/systemd/salt-minion.service_50-restarts
new file mode 100644
index 0000000..5dee5d7
--- /dev/null
+++ b/salt/files/systemd/salt-minion.service_50-restarts
@@ -0,0 +1,3 @@
+[Service]
+Restart=always
+RestartSec=3
diff --git a/salt/master/service.sls b/salt/master/service.sls
index 6cdff88..a95c1e6 100644
--- a/salt/master/service.sls
+++ b/salt/master/service.sls
@@ -109,6 +109,22 @@
     splay: 5
   {%- endif %}
 
+{%- if grains.get('init', None) == 'systemd' %}
+salt_master_systemd_override:
+  file.managed:
+    - name: /etc/systemd/system/{{ master.service }}.service.d/50-restarts.conf
+    - source: salt://salt/files/systemd/{{ master.service }}.service_50-restarts
+    - makedirs: True
+
+salt_master_systemd_reload:
+  module.wait:
+    - name: service.systemctl_reload
+    - onchanges:
+      - file: salt_master_systemd_override
+    - watch_in:
+      - service: salt_master_service
+{%- endif %}
+
 /srv/salt/env:
   file.directory:
   - user: root
diff --git a/salt/minion/base.sls b/salt/minion/base.sls
index a9b1714..0fba63e 100644
--- a/salt/minion/base.sls
+++ b/salt/minion/base.sls
@@ -64,6 +64,22 @@
     - onlyif: /bin/false
     {%- endif %}
 
+{%- if grains.get('init', None) == 'systemd' %}
+salt_minion_systemd_override:
+  file.managed:
+    - name: /etc/systemd/system/{{ minion.service }}.service.d/50-restarts.conf
+    - source: salt://salt/files/systemd/{{ minion.service }}.service_50-restarts
+    - makedirs: True
+
+salt_minion_systemd_reload:
+  module.wait:
+    - name: service.systemctl_reload
+    - onchanges:
+      - file: salt_minion_systemd_override
+    - watch_in:
+      - service: salt_minion_service
+{%- endif %}
+
 {#- Restart salt-minion if needed but after all states are executed #}
 salt_minion_service_restart:
   cmd.run:
diff --git a/salt/minion/env_vars.sls b/salt/minion/env_vars.sls
index e4d2680..f56dd19 100644
--- a/salt/minion/env_vars.sls
+++ b/salt/minion/env_vars.sls
@@ -1,8 +1,7 @@
 {%- from "salt/map.jinja" import minion,env_vars with context %}
 
 {%- if env_vars.engine is defined %}
-{%- if env_vars.engine == 'file' %}
-
+  {%- if env_vars.engine == 'file' %}
 /etc/default/salt-minion:
   file.managed:
   - source: salt://salt/files/etc_default_salt-minion
@@ -14,10 +13,11 @@
   - onchanges_in:
     - cmd: salt_minion_service_restart
 
-{%- if grains.get('init', None) == 'systemd' %}
-/etc/systemd/system/salt-minion.service.d/override.conf:
+    {%- if grains.get('init', None) == 'systemd' %}
+/etc/systemd/system/salt-minion.service.d/40-override:
   file.managed:
-  - source: salt://salt/files/systemd_minion_override.conf
+  - name: /etc/systemd/system/salt-minion.service.d/40-override
+  - source: salt://salt/files/systemd/salt-minion.service_40-override
   - user: root
   - makedirs: True
   - group: root
@@ -26,7 +26,6 @@
     - {{ minion.install_state }}
   - onchanges_in:
     - cmd: salt_minion_service_restart
-
-{%- endif %}
-{%- endif %}
+    {%- endif %}
+  {%- endif %}
 {%- endif %}
diff --git a/salt/minion/service.sls b/salt/minion/service.sls
index 436b27c..0280afc 100644
--- a/salt/minion/service.sls
+++ b/salt/minion/service.sls
@@ -125,6 +125,23 @@
     - onlyif: /bin/false
     {%- endif %}
 
+
+{%- if grains.get('init', None) == 'systemd' %}
+salt_minion_systemd_override:
+  file.managed:
+    - name: /etc/systemd/system/{{ minion.service }}.service.d/50-restarts.conf
+    - source: salt://salt/files/systemd/{{ minion.service }}.service_50-restarts
+    - makedirs: True
+
+salt_minion_systemd_reload:
+  module.wait:
+    - name: service.systemctl_reload
+    - onchanges:
+      - file: salt_minion_systemd_override
+    - watch_in:
+      - service: salt_minion_service
+{%- endif %}
+
 {#- Restart salt-minion if needed but after all states are executed #}
 salt_minion_service_restart:
   cmd.run: