设为首页 收藏本站
查看: 793|回复: 0

[经验分享] Puppet service资源介绍(二十五)

[复制链接]

尚未签到

发表于 2017-10-31 16:15:07 | 显示全部楼层 |阅读模式
service资源
        service资源主要对服务做启动、重启、关闭,监控进程的状态等.

service的参数:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
service { 'resource title':
  name       => # (namevar) The name of the service to run.  This name is...
  ensure     => # Whether a service should be running.  Valid...
  binary     => # The path to the daemon.  This is only used for...
  control    => # The control variable used to manage services...
  enable     => # Whether a service should be enabled to start at...
  flags      => # Specify a string of flags to pass to the startup
  hasrestart => # Specify that an init script has a `restart...
  hasstatus  => # Declare whether the service's init script has a...
  manifest   => # Specify a command to config a service, or a path
  path       => # The search path for finding init scripts....
  pattern    => # The pattern to search for in the process table...
  provider   => # The specific backend to use for this `service...
  restart    => # Specify a *restart* command manually.  If left...
  start      => # Specify a *start* command manually.  Most...
  status     => # Specify a *status* command manually.  This...
  stop       => # Specify a *stop* command...
  # ...plus any applicable metaparameters.
}




binary:指定二进制程序的系统路径,用于那些不支持init的操作系统.如果守护进程没有自启动脚本,可以通过此属性启动服务.

enable:指定服务在开机的时候是否启动,可以设置true和false值.

ensure:是否运行服务,running表示运行,stopped表示停止服务.

hasrestart:指出管理脚本是否支持restart值,如果不支持,就用stop值和start值实现restart效果.可以设置为true和false.

hasstatus:指出管理脚本是否支持status值.puppet用status值来判断服务是否已经在运行,如果系统不支持status值,puppet可以利用查找运行进程列表里面是否有服务名来判断服务是否在运行.可以设置为true和false.

name:守护进程的名字,如果记得不准确可以在/etc/init.d目录下面查找.

path:启动脚本的搜索路径,可以用冒号分割多个路径,或者用数组指定.

pattern:设置匹配进程的字符串,当服务停止时,通过进程列表来判断服务的状态,主要用于不支持init脚本的系统.

restart:指定用于重启服务的脚本,否则只能手动先停止该服务再启动该服务.

start:指定启动服务的命令,通常init模式的管理脚本都支持,不需要手工指定.

status:指定status命令,如果不指定,就从近乎才呢过列表查询该服务.

stop:指定停止服务的脚本.

provider:操作系统支持的init模式的管理脚本,支持base|daemontools|init,默认为init.


示例一:
启动httpd服务,设置开机自启动.

注意:启动服务的前提是httpd软件包已经安装.

1
2
3
4
service {"httpd":
    ensure => running,
    enable => true,
}



1
2
[iyunv@sh-web1 ~]# /etc/init.d/httpd status
httpd (pid  121592) is running...



1
2
[iyunv@sh-web1 ~]# chkconfig --list | grep httpd
httpd          0:off1:off2:on3:on4:on5:on6:off





示例二:
之前文章写过怎么将源码包封装成rpm包,下面是封装好的mysql rpm包,测试puppet代码.
1
2
3
4
5
[iyunv@sh-web1 ~]# rpm -ivh mysql-5.6.29-1.x86_64.rpm
Preparing...                ########################################### [100%]
   1:mysql                  ########################################### [100%]
`/usr/include/mysql/include' -> `/data/mysql/include'
[iyunv@sh-web1 ~]# source /etc/profile



安装目录在/data目录下.
1
2
[iyunv@sh-web1 ~]# ls /data/
mysql  mysqldata



启动脚本是/data的脚本cp一份放到/etc/init.d目录下.

下面是puppet启动mysql的代码.
1
2
3
4
5
6
7
8
9
10
11
12
[iyunv@sh-web1 ~]# cat mysqld.pp
service {"mysqld":
    ensure => running,
    enable => true,
    hasrestart => true,
    hasstatus => true,
    provider => init,
    path => "/etc/init.d",
    restart => "/etc/init.d/mysqld reload",
    start => "/etc/init.d/mysqld start",
    stop => "/etc/init.d/mysqld stop",
}





运行结果:
1
2
3
4
[iyunv@sh-web1 ~]# puppet apply mysqld.pp
Notice: Compiled catalog for sh-web1.localdomain in environment production in 0.06 seconds
Notice: /Stage[main]/Main/Service[mysqld]/ensure: ensure changed 'stopped' to 'running'
Notice: Finished catalog run in 2.44 seconds





查看结果是否启动.
1
2
[iyunv@sh-web1 ~]# /etc/init.d/mysqld status
MySQL running (123039)                                     [  OK  ]






运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-406344-1-1.html 上篇帖子: Puppet package资源介绍(二十四) 下篇帖子: Puppet exec资源介绍(二十六)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表