1.

Restart Using States?

Answer»

Now we can apply the workaround to restart the Minion in reliable way. The FOLLOWING example works on both UNIX-like and Windows OPERATING systems:

Restart Salt Minion:

cmd.run:
{%- if grains['kernel'] == 'Windows' %}
- name: 'C:saltsalt-call.bat --local service.restart salt-minion'
{%- ELSE %}
- name: 'salt-call --local service.restart salt-minion'
{%- endif %}
- BG: True
- onchanges:
- pkg: Upgrade Salt Minion

However, it requires more advanced tricks to upgrade from legacy version of Salt (before 2016.3.0), where executing commands in the background is not supported:

Restart Salt Minion:

cmd.run:
{%- if grains['kernel'] == 'Windows' %}
- name: 'start powershell "Restart-Service -Name salt-minion"'
{%- else %}
# fork and disown the process
- name: |-
exec 0>&- # close stdin
exec 1>&- # close stdout
exec 2>&- # close stderr
nohup salt-call --local service.restart salt-minion &
{%- endif %}

Now we can apply the workaround to restart the Minion in reliable way. The following example works on both UNIX-like and Windows operating systems:

Restart Salt Minion:

cmd.run:
{%- if grains['kernel'] == 'Windows' %}
- name: 'C:saltsalt-call.bat --local service.restart salt-minion'
{%- else %}
- name: 'salt-call --local service.restart salt-minion'
{%- endif %}
- bg: True
- onchanges:
- pkg: Upgrade Salt Minion

However, it requires more advanced tricks to upgrade from legacy version of Salt (before 2016.3.0), where executing commands in the background is not supported:

Restart Salt Minion:

cmd.run:
{%- if grains['kernel'] == 'Windows' %}
- name: 'start powershell "Restart-Service -Name salt-minion"'
{%- else %}
# fork and disown the process
- name: |-
exec 0>&- # close stdin
exec 1>&- # close stdout
exec 2>&- # close stderr
nohup salt-call --local service.restart salt-minion &
{%- endif %}



Discussion

No Comment Found