SaltStack 常用模块介绍 - service - pkg - file
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SaltStack 常用模块介绍 - service - pkg - file相关的知识,希望对你有一定的参考价值。
- salt ‘*‘ sys.state_doc service
-
salt-minion: ---------- 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: redis: service.running: - enable: True - reload: True - watch: - pkg: redis Note: More details regarding ``watch`` can be found in the :doc:`Requisites </ref/states/requisites>` documentation. service.dead: Ensure that the named service is dead by stopping the service if it 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 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.enabled: Verify that the service is enabled on boot, only use this state if you don‘t want to manage the running process, remember that if you want to enable a running service to use the enable: True option for the running or dead function. name The name of the init or rc script used to manage the service service.mod_watch: The service watcher, called to invoke the watch command. name The name of the init or rc script used to manage the service sfun The original function which triggered the mod_watch call (`service.running`, for example). sig The string to search for when looking for the service process with ps 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
salt-minion: - pkg.installed - pkg.latest - pkg.mod_aggregate - pkg.mod_init - pkg.purged - pkg.removed - pkg.uptodate
ES:
redis-install:
pkg.installed:
- pkgs:
- redis
service-start:
service.running:
- enable: True
- reload: True
- watch:
- pkg.redis-install
-
salt ‘*‘ sys.list_state_functions file salt-minion: - file.absent - file.accumulated - file.append - file.blockreplace - file.comment - file.copy - file.directory - file.exists - file.managed - file.missing - file.mknod - file.mod_run_check_cmd - file.patch - file.prepend - file.recurse - file.rename - file.replace - file.serialize - file.symlink - file.touch - file.uncomment
ES:
/tmp/test.txt:
file.managed:
- name: /tmp/test.txt
- source: salt://files/src.txt
- mkdirs: Truenginx: pkg.installed: - name: nginx - pkgs: - nginx - redis - watch_in: - file.file-copy file-copy: file.managed: - name: /etc/nginx/conf.d/default.conf - source: salt://nginx/files/default.conf - template: jinja - mkdirs: True - watch_in: - service.service-start
- cmd.service-reload service-start: service.running: - name: nginx - enable: True - reload: True
service-reload:
- cmd.run:
- `which nginx` -s reload
备注:上面的 sls中,存在一个bug,现象是,如果conf文件改变,nginx不会reload,配置不生效, 具体原因不清楚,不过可以使用出cmd模块解决。
以上是关于SaltStack 常用模块介绍 - service - pkg - file的主要内容,如果未能解决你的问题,请参考以下文章