WoJ
WoJ

Reputation: 30064

How to restart a systemd service with salt?

I am trying to build an .sls file which will always restart a service:

systemd-resolved:
  service.running:
    - restart: True

When deployed, this gives


      ID: systemd-resolved
Function: service.running
  Result: True
 Comment: The service systemd-resolved is already running
 Started: 23:46:49.999789
Duration: 53.068 ms
 Changes:

This is correct, the service is already running. What I was trying to convey with this command is to restart it. How to do that?

Note: I would like to avoid, if possible, an explicit command to be ran (as I feel it i snot very salt-like - this should rather be handled by the appropriate module):

'systemctl restart systemd-resolved':
  cmd.run

Upvotes: 2

Views: 18295

Answers (2)

user2664304
user2664304

Reputation: 35

Unfortunately this does not work if the service does not have the execreload command defined in the service file. The only way around this that I have found is to use cmd.run and systemctl restart service.

Upvotes: 0

Sufiyan Ghori
Sufiyan Ghori

Reputation: 18763

If you want your service to reload you need to set reload: True instead. Beside, If you only want to restart the service if there is any change in any other state, you need to use watch instead. for instance,

systemd-resolved:
  service.running:
    - enable: True
    - reload: True
    - watch:
      - pkg: <abc>

Upvotes: 6

Related Questions