我正在尝试创建一个安装 tomcat 的 puppet 模块。我让其他一切正常工作,模块下载 tomcat tar,提取它,删除包并从模板更改设置文件。我遇到的唯一问题是它不会自动启动 tomcat。如何设置它执行“sudo sh startup.sh”?
我尝试使用命令 => "sudo sh startup.sh",但我认为问题是它不能使用 sudo。有没有办法绕过那个或其他解决方案来启动 tomcat?
最佳答案
我建议你安装一个服务脚本,而不是声明一个 exec 来启动应用程序服务器。
这样您就可以依赖 service
资源类型的特性,它会负责检查服务的状态并确保它符合预期。
您可以找到一个示例脚本,它可以作为 tomcat.erb
here 放在模块的 templates/
目录中。 .
基本上,您接下来要做的是声明一个file
、exec
、service
资源三元组,如下所示(基于 RedHat 的操作系统的示例, Debian/Ubuntu 类似,除了 chkconfig
部分):
file { '/etc/init.d/tomcat':
ensure => present,
content => template('tomcat/tomcat.erb'),
mode => 'u=rwx,og=rw',
user => 'root',
group => 'root',
notify => Exec['add_tomcat_service'],
}
exec {'add_tomcat_service':
command => '/sbin/chkconfig --add tomcat',
path => ['/bin', '/sbin', '/usr/bin', '/usr/sbin'],
onlyif => "test `/sbin/chkconfig --list | /bin/grep tomcat | /usr/bin/wc -l` -eq 0",
before => Service['tomcat'],
}
service { 'tomcat':
ensure => started,
hasstatus => true,
hasrestart => true,
}
关于linux - sh startup.sh 使用 puppet 模块启动 tomcat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16571735/