问题
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