sh startup.sh start tomcat with puppet module

柔情痞子 提交于 2019-12-13 01:27:09

问题


I am trying to create a puppet module which installs tomcat. I got everything else working, the module downloads tomcat tar, extracts it, removes the package and changes the settings file from template. The only problem I have it won't start tomcat automatically. How do I set it to do "sudo sh startup.sh" ?

I tried with command => "sudo sh startup.sh" , but I think the problem is that it cant use sudo. Is there a way to bypass that or other solution to get tomcat start?


回答1:


I suggest you to install a service script instead of declaring an exec to start the application server.
This way you can rely on the features of the service resource type, which takes care for you of checking the status of the service and ensuring it is what it's expected to be.
You can find an example script that can be put in the templates/ directory of your module as tomcat.erb here.

Basically, what you would do then is declare a file, exec, service resource triplet as follows (example for RedHat based OSes, similar for Debian/Ubuntu except the chkconfig part):

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,
}


来源:https://stackoverflow.com/questions/16571735/sh-startup-sh-start-tomcat-with-puppet-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!