企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
~~~ [admin@master init]$ sudo salt 'node2*' sys.list_state_functions service node2.51yuki.cn: - service.dead - service.disabled - service.enabled - service.mod_watch - service.running (查看service模块支持哪些函数,其实service.running在状态模块中最常用) [admin@master init]$ sudo salt 'node2*' sys.state_doc service.running node2.51yuki.cn: ---------- service: Starting or restarting of services and daemons ============================================== Services are defined as system daemons typically started with system init or rc scripts, services can be defined as running or dead. httpd: service.running: [] The service can also be set to be started at runtime via the enable option: openvpn: service.running: - enable: True By default if a service is triggered to refresh due to a watch statement the service is by default restarted. If the desired behavior is to reload the service, then set the reload value to True: (服务默认情况是restart,如果要执行reload,你们就要把reload设置为true) 案例: redis: service.running: - enable: True - reload: True - watch: - pkg: redis 或者: service.running: - name: redis - enable: True - reload: True - watch - pkg: redis Note: More details regarding ``watch`` can be found in the :doc:`Requisites </ref/states/requisites>` documentation. service.running: Verify that the service is running name The name of the init or rc script used to manage the service enable Set the service to be enabled at boot time, True sets the service to be enabled, False sets the named service to be disabled. The default is None, which does not enable or disable anything. sig The string to search for when looking for the service process with ps 总结: 1、常用的参数有如下 enable: True reload: True ~~~ 案例: service.running: - name: sshd - enable: True - reload: True - require: - file: ssh-managed 关闭服务: - service.disabled ~~~ service.disabled: Verify that the service is disabled on boot, only use this state if you don't want to manage the running process, remember that if you want to disable a service to use the enable: False option for the running or dead function. name The name of the init or rc script used to manage the service ~~~ 案例: service.disabled: - name: rpcbind 2)判断目标服务器上某个服务是否可用 [admin@master init]$ sudo salt 'node2.51yuki.cn' service.available sshd node2.51yuki.cn: True 3)重新加载指定服务 [admin@master init]$ sudo salt 'node2*' service.reload sshd node2.51yuki.cn: True 4) 重新启动指定服务 [admin@master init]$ sudo salt 'node2*' service.restart sshd node2.51yuki.cn: True 5) 查看指定服务的状态 [admin@master init]$ sudo salt 'node2*' service.status sshd node2.51yuki.cn: True