service用法
[root@ansible ~]# ansible-doc -s service less 436 Copyright (C) 1984-2009 Mark Nudelman less comes with NO WARRANTY, to the extent permitted by law. For information about the terms of redistribution, see the file named README in the less distribution. Homepage: http://www.greenwoodsoftware.com/less - name: Manage services. action: service arguments # Additional arguments provided on the command line enabled # Whether the service should start on boot. *At least one of state and enabled are required.* name= # Name of the service. pattern # If the service does not respond to the status command, name a substring to look for as would be found in the output of the `ps‘ command as a stand-in for a status result. If the string is found, the service will be assumed to be running. runlevel # For OpenRC init scripts (ex: Gentoo) only. The runlevel that this service belongs to. sleep # If the service is being `restarted‘ then sleep this many seconds between the stop and start command. This helps to workaround badly behaving init scripts that exit immediately after signaling a process to stop. state # `started‘/`stopped‘ are idempotent actions that will not run commands unless necessary. `restarted‘ will always bounce the service. `reloaded‘ will always reload. *At least one of state and enabled are required.*
该模块包含如下选项:
arguments:给命令行提供一些选项
enabled:是否开机启动 yes|no
name:必选项,服务名称
pattern:定义一个模式,如果通过status指令来查看服务的状态时,没有响应,就会通过ps指令在进程中根据该模式进行查找,如果匹配到,则认为该服务依然在运行
runlevel:运行级别
sleep:如果执行了restarted,在则stop和start之间沉睡几秒钟
state:对当前服务执行启动,停止、重启、重新加载等操作(started,stopped,restarted,reloaded)
查看web组中的httpd状态
[root@ansible ~]# ansible web -a ‘service httpd status‘ web | FAILED | rc=3 >> httpd is stopped
使用service模块启动
[root@ansible ~]# ansible web -m service -a ‘name=httpd state=started‘ web | SUCCESS => { "changed": true, "name": "httpd", "state": "started" }
查看httpd运行状态
[root@ansible ~]# ansible web -a ‘service httpd status‘ web | SUCCESS | rc=0 >> httpd (pid 5268) is running...
本文出自 “村里的男孩” 博客,请务必保留此出处http://noodle.blog.51cto.com/2925423/1769487
原文地址:http://noodle.blog.51cto.com/2925423/1769487