~~~
[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
- 第一章:saltstack的基本介紹
- 第二章:saltstack的安裝部署
- 第一節:在centos7系統上安裝saltstack工具
- 第二節:在windows server 2008上安裝salt-minion
- 第三章: saltstack的配置管理
- 第一節:salt-master配置
- 第二節:salt-minion配置
- 第三節:了解YAML
- 第四節:salt-master配置文件詳解
- 第五節:了解Jinja2
- 第六節:配置普通用戶可以運行saltstack的模塊
- 第四章:遠程執行
- 第一節:遠程執行基礎介紹
- 第二節:目標定位
- 一、全局及正則表達式匹配
- 二、列表匹配
- 三、Grains
- 四: Pillar
- 五:subnet and ip
- 六:組合匹配
- 七: node group
- 第三節:常用模塊
- 一、查看幫助
- 二、Network模塊
- 三、Service模塊
- 四:State模塊
- 五、Cron模塊
- 六、File模塊
- 七、iptables模塊
- 八、pkg包管理
- 第四節:Salt其他命令
- 一、salt-cp(拷貝文件)
- 二、salt-ssh
- 三、salt-key
- 第五節:saltstack返回程序
- 第一節:返回保持到數據庫(mysql)
- 第五章:配置管理
- 第一節:簡單入門
- 第二節:狀態間關系
- 第六章:數據系統
- 第一節:grains
- 第二節:pillar
- 第七章:saltstack配置管理
- 第一節:系統初始化操作
- 第二節:功能模塊
- 一、haproxy模塊
- 二、keepalived模塊
- 三、nginx模塊
- 四: pcre模塊
- 五: zlib模塊
- 六:user模塊
- 七:php模塊
- 第三節:業務模塊
- 第一節:haproxy代理
- 第二節:keepalived業務
- 第八章:自動化管理工具saltstack
- 第一節:文件管理
- 第二節:軟件管理
- 第三節:服務管理
- 第四節:sysctl模塊管理